﻿<?xml version="1.0" encoding="utf-8" ?>
<Jass>
  <Natives>
    <Variable Name="false" Type="boolean" Value="false">
      <![CDATA[constant boolean            false                           = false]]>
    </Variable>
    <Variable Name="true" Type="boolean" Value="true">
      <![CDATA[constant boolean            true                           = true]]>
    </Variable>

    <Variable Name="FALSE" Type="boolean" Value="false">
      <![CDATA[constant boolean            FALSE                           = false]]>
    </Variable>

    <Variable Name="TRUE" Type="boolean" Value="true">
      <![CDATA[constant boolean            TRUE                            = true]]>
    </Variable>

    <Variable Name="JASS_MAX_ARRAY_SIZE" Type="integer" Value="8192">
      <![CDATA[constant integer            JASS_MAX_ARRAY_SIZE             = 8192]]>
    </Variable>

    <Variable Name="PLAYER_NEUTRAL_PASSIVE" Type="integer" Value="15">
      <![CDATA[constant integer            PLAYER_NEUTRAL_PASSIVE          = 15]]>
    </Variable>

    <Variable Name="PLAYER_NEUTRAL_AGGRESSIVE" Type="integer" Value="12">
      <![CDATA[constant integer            PLAYER_NEUTRAL_AGGRESSIVE       = 12]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_RED" Type="playercolor" Value="ConvertPlayerColor(0)">
      <![CDATA[constant playercolor        PLAYER_COLOR_RED                = ConvertPlayerColor(0)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_BLUE" Type="playercolor" Value="ConvertPlayerColor(1)">
      <![CDATA[constant playercolor        PLAYER_COLOR_BLUE               = ConvertPlayerColor(1)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_CYAN" Type="playercolor" Value="ConvertPlayerColor(2)">
      <![CDATA[constant playercolor        PLAYER_COLOR_CYAN               = ConvertPlayerColor(2)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_PURPLE" Type="playercolor" Value="ConvertPlayerColor(3)">
      <![CDATA[constant playercolor        PLAYER_COLOR_PURPLE             = ConvertPlayerColor(3)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_YELLOW" Type="playercolor" Value="ConvertPlayerColor(4)">
      <![CDATA[constant playercolor        PLAYER_COLOR_YELLOW             = ConvertPlayerColor(4)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_ORANGE" Type="playercolor" Value="ConvertPlayerColor(5)">
      <![CDATA[constant playercolor        PLAYER_COLOR_ORANGE             = ConvertPlayerColor(5)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_GREEN" Type="playercolor" Value="ConvertPlayerColor(6)">
      <![CDATA[constant playercolor        PLAYER_COLOR_GREEN              = ConvertPlayerColor(6)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_PINK" Type="playercolor" Value="ConvertPlayerColor(7)">
      <![CDATA[constant playercolor        PLAYER_COLOR_PINK               = ConvertPlayerColor(7)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_LIGHT_GRAY" Type="playercolor" Value="ConvertPlayerColor(8)">
      <![CDATA[constant playercolor        PLAYER_COLOR_LIGHT_GRAY         = ConvertPlayerColor(8)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_LIGHT_BLUE" Type="playercolor" Value="ConvertPlayerColor(9)">
      <![CDATA[constant playercolor        PLAYER_COLOR_LIGHT_BLUE         = ConvertPlayerColor(9)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_AQUA" Type="playercolor" Value="ConvertPlayerColor(10)">
      <![CDATA[constant playercolor        PLAYER_COLOR_AQUA               = ConvertPlayerColor(10)]]>
    </Variable>

    <Variable Name="PLAYER_COLOR_BROWN" Type="playercolor" Value="ConvertPlayerColor(11)">
      <![CDATA[constant playercolor        PLAYER_COLOR_BROWN              = ConvertPlayerColor(11)]]>
    </Variable>

    <Variable Name="RACE_HUMAN" Type="race" Value="ConvertRace(1)">
      <![CDATA[constant race               RACE_HUMAN                      = ConvertRace(1)]]>
    </Variable>

    <Variable Name="RACE_ORC" Type="race" Value="ConvertRace(2)">
      <![CDATA[constant race               RACE_ORC                        = ConvertRace(2)]]>
    </Variable>

    <Variable Name="RACE_UNDEAD" Type="race" Value="ConvertRace(3)">
      <![CDATA[constant race               RACE_UNDEAD                     = ConvertRace(3)]]>
    </Variable>

    <Variable Name="RACE_NIGHTELF" Type="race" Value="ConvertRace(4)">
      <![CDATA[constant race               RACE_NIGHTELF                   = ConvertRace(4)]]>
    </Variable>

    <Variable Name="RACE_DEMON" Type="race" Value="ConvertRace(5)">
      <![CDATA[constant race               RACE_DEMON                      = ConvertRace(5)]]>
    </Variable>

    <Variable Name="RACE_OTHER" Type="race" Value="ConvertRace(7)">
      <![CDATA[constant race               RACE_OTHER                      = ConvertRace(7)]]>
    </Variable>

    <Variable Name="PLAYER_GAME_RESULT_VICTORY" Type="playergameresult" Value="ConvertPlayerGameResult(0)">
      <![CDATA[constant playergameresult   PLAYER_GAME_RESULT_VICTORY      = ConvertPlayerGameResult(0)]]>
    </Variable>

    <Variable Name="PLAYER_GAME_RESULT_DEFEAT" Type="playergameresult" Value="ConvertPlayerGameResult(1)">
      <![CDATA[constant playergameresult   PLAYER_GAME_RESULT_DEFEAT       = ConvertPlayerGameResult(1)]]>
    </Variable>

    <Variable Name="PLAYER_GAME_RESULT_TIE" Type="playergameresult" Value="ConvertPlayerGameResult(2)">
      <![CDATA[constant playergameresult   PLAYER_GAME_RESULT_TIE          = ConvertPlayerGameResult(2)]]>
    </Variable>

    <Variable Name="PLAYER_GAME_RESULT_NEUTRAL" Type="playergameresult" Value="ConvertPlayerGameResult(3)">
      <![CDATA[constant playergameresult   PLAYER_GAME_RESULT_NEUTRAL      = ConvertPlayerGameResult(3)]]>
    </Variable>

    <Variable Name="ALLIANCE_PASSIVE" Type="alliancetype" Value="ConvertAllianceType(0)">
      <![CDATA[constant alliancetype       ALLIANCE_PASSIVE                = ConvertAllianceType(0)]]>
    </Variable>

    <Variable Name="ALLIANCE_HELP_REQUEST" Type="alliancetype" Value="ConvertAllianceType(1)">
      <![CDATA[constant alliancetype       ALLIANCE_HELP_REQUEST           = ConvertAllianceType(1)]]>
    </Variable>

    <Variable Name="ALLIANCE_HELP_RESPONSE" Type="alliancetype" Value="ConvertAllianceType(2)">
      <![CDATA[constant alliancetype       ALLIANCE_HELP_RESPONSE          = ConvertAllianceType(2)]]>
    </Variable>

    <Variable Name="ALLIANCE_SHARED_XP" Type="alliancetype" Value="ConvertAllianceType(3)">
      <![CDATA[constant alliancetype       ALLIANCE_SHARED_XP              = ConvertAllianceType(3)]]>
    </Variable>

    <Variable Name="ALLIANCE_SHARED_SPELLS" Type="alliancetype" Value="ConvertAllianceType(4)">
      <![CDATA[constant alliancetype       ALLIANCE_SHARED_SPELLS          = ConvertAllianceType(4)]]>
    </Variable>

    <Variable Name="ALLIANCE_SHARED_VISION" Type="alliancetype" Value="ConvertAllianceType(5)">
      <![CDATA[constant alliancetype       ALLIANCE_SHARED_VISION          = ConvertAllianceType(5)]]>
    </Variable>

    <Variable Name="ALLIANCE_SHARED_CONTROL" Type="alliancetype" Value="ConvertAllianceType(6)">
      <![CDATA[constant alliancetype       ALLIANCE_SHARED_CONTROL         = ConvertAllianceType(6)]]>
    </Variable>

    <Variable Name="ALLIANCE_SHARED_ADVANCED_CONTROL" Type="alliancetype" Value="ConvertAllianceType(7)">
      <![CDATA[constant alliancetype       ALLIANCE_SHARED_ADVANCED_CONTROL= ConvertAllianceType(7)]]>
    </Variable>

    <Variable Name="ALLIANCE_RESCUABLE" Type="alliancetype" Value="ConvertAllianceType(8)">
      <![CDATA[constant alliancetype       ALLIANCE_RESCUABLE              = ConvertAllianceType(8)]]>
    </Variable>

    <Variable Name="ALLIANCE_SHARED_VISION_FORCED" Type="alliancetype" Value="ConvertAllianceType(9)">
      <![CDATA[constant alliancetype       ALLIANCE_SHARED_VISION_FORCED   = ConvertAllianceType(9)]]>
    </Variable>

    <Variable Name="VERSION_REIGN_OF_CHAOS" Type="version" Value="ConvertVersion(0)">
      <![CDATA[constant version            VERSION_REIGN_OF_CHAOS          = ConvertVersion(0)]]>
    </Variable>

    <Variable Name="VERSION_FROZEN_THRONE" Type="version" Value="ConvertVersion(1)">
      <![CDATA[constant version            VERSION_FROZEN_THRONE           = ConvertVersion(1)]]>
    </Variable>

    <Variable Name="RACE_PREF_HUMAN" Type="racepreference" Value="ConvertRacePref(1)">
      <![CDATA[constant racepreference     RACE_PREF_HUMAN                     = ConvertRacePref(1)]]>
    </Variable>

    <Variable Name="RACE_PREF_ORC" Type="racepreference" Value="ConvertRacePref(2)">
      <![CDATA[constant racepreference     RACE_PREF_ORC                       = ConvertRacePref(2)]]>
    </Variable>

    <Variable Name="RACE_PREF_NIGHTELF" Type="racepreference" Value="ConvertRacePref(4)">
      <![CDATA[constant racepreference     RACE_PREF_NIGHTELF                  = ConvertRacePref(4)]]>
    </Variable>

    <Variable Name="RACE_PREF_UNDEAD" Type="racepreference" Value="ConvertRacePref(8)">
      <![CDATA[constant racepreference     RACE_PREF_UNDEAD                    = ConvertRacePref(8)]]>
    </Variable>

    <Variable Name="RACE_PREF_DEMON" Type="racepreference" Value="ConvertRacePref(16)">
      <![CDATA[constant racepreference     RACE_PREF_DEMON                     = ConvertRacePref(16)]]>
    </Variable>

    <Variable Name="RACE_PREF_RANDOM" Type="racepreference" Value="ConvertRacePref(32)">
      <![CDATA[constant racepreference     RACE_PREF_RANDOM                    = ConvertRacePref(32)]]>
    </Variable>

    <Variable Name="RACE_PREF_USER_SELECTABLE" Type="racepreference" Value="ConvertRacePref(64)">
      <![CDATA[constant racepreference     RACE_PREF_USER_SELECTABLE           = ConvertRacePref(64)]]>
    </Variable>

    <Variable Name="MAP_CONTROL_USER" Type="mapcontrol" Value="ConvertMapControl(0)">
      <![CDATA[constant mapcontrol         MAP_CONTROL_USER                    = ConvertMapControl(0)]]>
    </Variable>

    <Variable Name="MAP_CONTROL_COMPUTER" Type="mapcontrol" Value="ConvertMapControl(1)">
      <![CDATA[constant mapcontrol         MAP_CONTROL_COMPUTER                = ConvertMapControl(1)]]>
    </Variable>

    <Variable Name="MAP_CONTROL_RESCUABLE" Type="mapcontrol" Value="ConvertMapControl(2)">
      <![CDATA[constant mapcontrol         MAP_CONTROL_RESCUABLE               = ConvertMapControl(2)]]>
    </Variable>

    <Variable Name="MAP_CONTROL_NEUTRAL" Type="mapcontrol" Value="ConvertMapControl(3)">
      <![CDATA[constant mapcontrol         MAP_CONTROL_NEUTRAL                 = ConvertMapControl(3)]]>
    </Variable>

    <Variable Name="MAP_CONTROL_CREEP" Type="mapcontrol" Value="ConvertMapControl(4)">
      <![CDATA[constant mapcontrol         MAP_CONTROL_CREEP                   = ConvertMapControl(4)]]>
    </Variable>

    <Variable Name="MAP_CONTROL_NONE" Type="mapcontrol" Value="ConvertMapControl(5)">
      <![CDATA[constant mapcontrol         MAP_CONTROL_NONE                    = ConvertMapControl(5)]]>
    </Variable>

    <Variable Name="GAME_TYPE_MELEE" Type="gametype" Value="ConvertGameType(1)">
      <![CDATA[constant gametype           GAME_TYPE_MELEE                     = ConvertGameType(1)]]>
    </Variable>

    <Variable Name="GAME_TYPE_FFA" Type="gametype" Value="ConvertGameType(2)">
      <![CDATA[constant gametype           GAME_TYPE_FFA                       = ConvertGameType(2)]]>
    </Variable>

    <Variable Name="GAME_TYPE_USE_MAP_SETTINGS" Type="gametype" Value="ConvertGameType(4)">
      <![CDATA[constant gametype           GAME_TYPE_USE_MAP_SETTINGS          = ConvertGameType(4)]]>
    </Variable>

    <Variable Name="GAME_TYPE_BLIZ" Type="gametype" Value="ConvertGameType(8)">
      <![CDATA[constant gametype           GAME_TYPE_BLIZ                      = ConvertGameType(8)]]>
    </Variable>

    <Variable Name="GAME_TYPE_ONE_ON_ONE" Type="gametype" Value="ConvertGameType(16)">
      <![CDATA[constant gametype           GAME_TYPE_ONE_ON_ONE                = ConvertGameType(16)]]>
    </Variable>

    <Variable Name="GAME_TYPE_TWO_TEAM_PLAY" Type="gametype" Value="ConvertGameType(32)">
      <![CDATA[constant gametype           GAME_TYPE_TWO_TEAM_PLAY             = ConvertGameType(32)]]>
    </Variable>

    <Variable Name="GAME_TYPE_THREE_TEAM_PLAY" Type="gametype" Value="ConvertGameType(64)">
      <![CDATA[constant gametype           GAME_TYPE_THREE_TEAM_PLAY           = ConvertGameType(64)]]>
    </Variable>

    <Variable Name="GAME_TYPE_FOUR_TEAM_PLAY" Type="gametype" Value="ConvertGameType(128)">
      <![CDATA[constant gametype           GAME_TYPE_FOUR_TEAM_PLAY            = ConvertGameType(128)]]>
    </Variable>

    <Variable Name="MAP_FOG_HIDE_TERRAIN" Type="mapflag" Value="ConvertMapFlag(1)">
      <![CDATA[constant mapflag            MAP_FOG_HIDE_TERRAIN                = ConvertMapFlag(1)]]>
    </Variable>

    <Variable Name="MAP_FOG_MAP_EXPLORED" Type="mapflag" Value="ConvertMapFlag(2)">
      <![CDATA[constant mapflag            MAP_FOG_MAP_EXPLORED                = ConvertMapFlag(2)]]>
    </Variable>

    <Variable Name="MAP_FOG_ALWAYS_VISIBLE" Type="mapflag" Value="ConvertMapFlag(4)">
      <![CDATA[constant mapflag            MAP_FOG_ALWAYS_VISIBLE              = ConvertMapFlag(4)]]>
    </Variable>

    <Variable Name="MAP_USE_HANDICAPS" Type="mapflag" Value="ConvertMapFlag(8)">
      <![CDATA[constant mapflag            MAP_USE_HANDICAPS                   = ConvertMapFlag(8)]]>
    </Variable>

    <Variable Name="MAP_OBSERVERS" Type="mapflag" Value="ConvertMapFlag(16)">
      <![CDATA[constant mapflag            MAP_OBSERVERS                       = ConvertMapFlag(16)]]>
    </Variable>

    <Variable Name="MAP_OBSERVERS_ON_DEATH" Type="mapflag" Value="ConvertMapFlag(32)">
      <![CDATA[constant mapflag            MAP_OBSERVERS_ON_DEATH              = ConvertMapFlag(32)]]>
    </Variable>

    <Variable Name="MAP_FIXED_COLORS" Type="mapflag" Value="ConvertMapFlag(128)">
      <![CDATA[constant mapflag            MAP_FIXED_COLORS                    = ConvertMapFlag(128)]]>
    </Variable>

    <Variable Name="MAP_LOCK_RESOURCE_TRADING" Type="mapflag" Value="ConvertMapFlag(256)">
      <![CDATA[constant mapflag            MAP_LOCK_RESOURCE_TRADING           = ConvertMapFlag(256)]]>
    </Variable>

    <Variable Name="MAP_RESOURCE_TRADING_ALLIES_ONLY" Type="mapflag" Value="ConvertMapFlag(512)">
      <![CDATA[constant mapflag            MAP_RESOURCE_TRADING_ALLIES_ONLY    = ConvertMapFlag(512)]]>
    </Variable>

    <Variable Name="MAP_LOCK_ALLIANCE_CHANGES" Type="mapflag" Value="ConvertMapFlag(1024)">
      <![CDATA[constant mapflag            MAP_LOCK_ALLIANCE_CHANGES           = ConvertMapFlag(1024)]]>
    </Variable>

    <Variable Name="MAP_ALLIANCE_CHANGES_HIDDEN" Type="mapflag" Value="ConvertMapFlag(2048)">
      <![CDATA[constant mapflag            MAP_ALLIANCE_CHANGES_HIDDEN         = ConvertMapFlag(2048)]]>
    </Variable>

    <Variable Name="MAP_CHEATS" Type="mapflag" Value="ConvertMapFlag(4096)">
      <![CDATA[constant mapflag            MAP_CHEATS                          = ConvertMapFlag(4096)]]>
    </Variable>

    <Variable Name="MAP_CHEATS_HIDDEN" Type="mapflag" Value="ConvertMapFlag(8192)">
      <![CDATA[constant mapflag            MAP_CHEATS_HIDDEN                   = ConvertMapFlag(8192)]]>
    </Variable>

    <Variable Name="MAP_LOCK_SPEED" Type="mapflag" Value="ConvertMapFlag(8192*2)">
      <![CDATA[constant mapflag            MAP_LOCK_SPEED                      = ConvertMapFlag(8192*2)]]>
    </Variable>

    <Variable Name="MAP_LOCK_RANDOM_SEED" Type="mapflag" Value="ConvertMapFlag(8192*4)">
      <![CDATA[constant mapflag            MAP_LOCK_RANDOM_SEED                = ConvertMapFlag(8192*4)]]>
    </Variable>

    <Variable Name="MAP_SHARED_ADVANCED_CONTROL" Type="mapflag" Value="ConvertMapFlag(8192*8)">
      <![CDATA[constant mapflag            MAP_SHARED_ADVANCED_CONTROL         = ConvertMapFlag(8192*8)]]>
    </Variable>

    <Variable Name="MAP_RANDOM_HERO" Type="mapflag" Value="ConvertMapFlag(8192*16)">
      <![CDATA[constant mapflag            MAP_RANDOM_HERO                     = ConvertMapFlag(8192*16)]]>
    </Variable>

    <Variable Name="MAP_RANDOM_RACES" Type="mapflag" Value="ConvertMapFlag(8192*32)">
      <![CDATA[constant mapflag            MAP_RANDOM_RACES                    = ConvertMapFlag(8192*32)]]>
    </Variable>

    <Variable Name="MAP_RELOADED" Type="mapflag" Value="ConvertMapFlag(8192*64)">
      <![CDATA[constant mapflag            MAP_RELOADED                        = ConvertMapFlag(8192*64)]]>
    </Variable>

    <Variable Name="MAP_PLACEMENT_RANDOM" Type="placement" Value="ConvertPlacement(0)">
      <![CDATA[constant placement          MAP_PLACEMENT_RANDOM                = ConvertPlacement(0)   // random among all slots]]>
    </Variable>

    <Variable Name="MAP_PLACEMENT_FIXED" Type="placement" Value="ConvertPlacement(1)">
      <![CDATA[constant placement          MAP_PLACEMENT_FIXED                 = ConvertPlacement(1)   // player 0 in start loc 0...]]>
    </Variable>

    <Variable Name="MAP_PLACEMENT_USE_MAP_SETTINGS" Type="placement" Value="ConvertPlacement(2)">
      <![CDATA[constant placement          MAP_PLACEMENT_USE_MAP_SETTINGS      = ConvertPlacement(2)   // whatever was specified by the script]]>
    </Variable>

    <Variable Name="MAP_PLACEMENT_TEAMS_TOGETHER" Type="placement" Value="ConvertPlacement(3)">
      <![CDATA[constant placement          MAP_PLACEMENT_TEAMS_TOGETHER        = ConvertPlacement(3)   // random with allies next to each other    ]]>
    </Variable>

    <Variable Name="MAP_LOC_PRIO_LOW" Type="startlocprio" Value="ConvertStartLocPrio(0)">
      <![CDATA[constant startlocprio       MAP_LOC_PRIO_LOW                    = ConvertStartLocPrio(0)]]>
    </Variable>

    <Variable Name="MAP_LOC_PRIO_HIGH" Type="startlocprio" Value="ConvertStartLocPrio(1)">
      <![CDATA[constant startlocprio       MAP_LOC_PRIO_HIGH                   = ConvertStartLocPrio(1)]]>
    </Variable>

    <Variable Name="MAP_LOC_PRIO_NOT" Type="startlocprio" Value="ConvertStartLocPrio(2)">
      <![CDATA[constant startlocprio       MAP_LOC_PRIO_NOT                    = ConvertStartLocPrio(2)]]>
    </Variable>

    <Variable Name="MAP_DENSITY_NONE" Type="mapdensity" Value="ConvertMapDensity(0)">
      <![CDATA[constant mapdensity         MAP_DENSITY_NONE                    = ConvertMapDensity(0)]]>
    </Variable>

    <Variable Name="MAP_DENSITY_LIGHT" Type="mapdensity" Value="ConvertMapDensity(1)">
      <![CDATA[constant mapdensity         MAP_DENSITY_LIGHT                   = ConvertMapDensity(1)]]>
    </Variable>

    <Variable Name="MAP_DENSITY_MEDIUM" Type="mapdensity" Value="ConvertMapDensity(2)">
      <![CDATA[constant mapdensity         MAP_DENSITY_MEDIUM                  = ConvertMapDensity(2)]]>
    </Variable>

    <Variable Name="MAP_DENSITY_HEAVY" Type="mapdensity" Value="ConvertMapDensity(3)">
      <![CDATA[constant mapdensity         MAP_DENSITY_HEAVY                   = ConvertMapDensity(3)]]>
    </Variable>

    <Variable Name="MAP_DIFFICULTY_EASY" Type="gamedifficulty" Value="ConvertGameDifficulty(0)">
      <![CDATA[constant gamedifficulty     MAP_DIFFICULTY_EASY                 = ConvertGameDifficulty(0)]]>
    </Variable>

    <Variable Name="MAP_DIFFICULTY_NORMAL" Type="gamedifficulty" Value="ConvertGameDifficulty(1)">
      <![CDATA[constant gamedifficulty     MAP_DIFFICULTY_NORMAL               = ConvertGameDifficulty(1)]]>
    </Variable>

    <Variable Name="MAP_DIFFICULTY_HARD" Type="gamedifficulty" Value="ConvertGameDifficulty(2)">
      <![CDATA[constant gamedifficulty     MAP_DIFFICULTY_HARD                 = ConvertGameDifficulty(2)]]>
    </Variable>

    <Variable Name="MAP_DIFFICULTY_INSANE" Type="gamedifficulty" Value="ConvertGameDifficulty(3)">
      <![CDATA[constant gamedifficulty     MAP_DIFFICULTY_INSANE               = ConvertGameDifficulty(3)]]>
    </Variable>

    <Variable Name="MAP_SPEED_SLOWEST" Type="gamespeed" Value="ConvertGameSpeed(0)">
      <![CDATA[constant gamespeed          MAP_SPEED_SLOWEST                   = ConvertGameSpeed(0)]]>
    </Variable>

    <Variable Name="MAP_SPEED_SLOW" Type="gamespeed" Value="ConvertGameSpeed(1)">
      <![CDATA[constant gamespeed          MAP_SPEED_SLOW                      = ConvertGameSpeed(1)]]>
    </Variable>

    <Variable Name="MAP_SPEED_NORMAL" Type="gamespeed" Value="ConvertGameSpeed(2)">
      <![CDATA[constant gamespeed          MAP_SPEED_NORMAL                    = ConvertGameSpeed(2)]]>
    </Variable>

    <Variable Name="MAP_SPEED_FAST" Type="gamespeed" Value="ConvertGameSpeed(3)">
      <![CDATA[constant gamespeed          MAP_SPEED_FAST                      = ConvertGameSpeed(3)]]>
    </Variable>

    <Variable Name="MAP_SPEED_FASTEST" Type="gamespeed" Value="ConvertGameSpeed(4)">
      <![CDATA[constant gamespeed          MAP_SPEED_FASTEST                   = ConvertGameSpeed(4)]]>
    </Variable>

    <Variable Name="PLAYER_SLOT_STATE_EMPTY" Type="playerslotstate" Value="ConvertPlayerSlotState(0)">
      <![CDATA[constant playerslotstate    PLAYER_SLOT_STATE_EMPTY             = ConvertPlayerSlotState(0)]]>
    </Variable>

    <Variable Name="PLAYER_SLOT_STATE_PLAYING" Type="playerslotstate" Value="ConvertPlayerSlotState(1)">
      <![CDATA[constant playerslotstate    PLAYER_SLOT_STATE_PLAYING           = ConvertPlayerSlotState(1)]]>
    </Variable>

    <Variable Name="PLAYER_SLOT_STATE_LEFT" Type="playerslotstate" Value="ConvertPlayerSlotState(2)">
      <![CDATA[constant playerslotstate    PLAYER_SLOT_STATE_LEFT              = ConvertPlayerSlotState(2)]]>
    </Variable>

    <Variable Name="SOUND_VOLUMEGROUP_UNITMOVEMENT" Type="volumegroup" Value="ConvertVolumeGroup(0)">
      <![CDATA[constant volumegroup        SOUND_VOLUMEGROUP_UNITMOVEMENT      = ConvertVolumeGroup(0)]]>
    </Variable>

    <Variable Name="SOUND_VOLUMEGROUP_UNITSOUNDS" Type="volumegroup" Value="ConvertVolumeGroup(1)">
      <![CDATA[constant volumegroup        SOUND_VOLUMEGROUP_UNITSOUNDS        = ConvertVolumeGroup(1)]]>
    </Variable>

    <Variable Name="SOUND_VOLUMEGROUP_COMBAT" Type="volumegroup" Value="ConvertVolumeGroup(2)">
      <![CDATA[constant volumegroup        SOUND_VOLUMEGROUP_COMBAT            = ConvertVolumeGroup(2)]]>
    </Variable>

    <Variable Name="SOUND_VOLUMEGROUP_SPELLS" Type="volumegroup" Value="ConvertVolumeGroup(3)">
      <![CDATA[constant volumegroup        SOUND_VOLUMEGROUP_SPELLS            = ConvertVolumeGroup(3)]]>
    </Variable>

    <Variable Name="SOUND_VOLUMEGROUP_UI" Type="volumegroup" Value="ConvertVolumeGroup(4)">
      <![CDATA[constant volumegroup        SOUND_VOLUMEGROUP_UI                = ConvertVolumeGroup(4)]]>
    </Variable>

    <Variable Name="SOUND_VOLUMEGROUP_MUSIC" Type="volumegroup" Value="ConvertVolumeGroup(5)">
      <![CDATA[constant volumegroup        SOUND_VOLUMEGROUP_MUSIC             = ConvertVolumeGroup(5)]]>
    </Variable>

    <Variable Name="SOUND_VOLUMEGROUP_AMBIENTSOUNDS" Type="volumegroup" Value="ConvertVolumeGroup(6)">
      <![CDATA[constant volumegroup        SOUND_VOLUMEGROUP_AMBIENTSOUNDS     = ConvertVolumeGroup(6)]]>
    </Variable>

    <Variable Name="SOUND_VOLUMEGROUP_FIRE" Type="volumegroup" Value="ConvertVolumeGroup(7)">
      <![CDATA[constant volumegroup        SOUND_VOLUMEGROUP_FIRE              = ConvertVolumeGroup(7)]]>
    </Variable>

    <Variable Name="GAME_STATE_DIVINE_INTERVENTION" Type="igamestate" Value="ConvertIGameState(0)">
      <![CDATA[constant igamestate GAME_STATE_DIVINE_INTERVENTION          = ConvertIGameState(0)]]>
    </Variable>

    <Variable Name="GAME_STATE_DISCONNECTED" Type="igamestate" Value="ConvertIGameState(1)">
      <![CDATA[constant igamestate GAME_STATE_DISCONNECTED                 = ConvertIGameState(1)]]>
    </Variable>

    <Variable Name="GAME_STATE_TIME_OF_DAY" Type="fgamestate" Value="ConvertFGameState(2)">
      <![CDATA[constant fgamestate GAME_STATE_TIME_OF_DAY                  = ConvertFGameState(2)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_GAME_RESULT" Type="playerstate" Value="ConvertPlayerState(0)">
      <![CDATA[constant playerstate PLAYER_STATE_GAME_RESULT               = ConvertPlayerState(0)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_RESOURCE_GOLD" Type="playerstate" Value="ConvertPlayerState(1)">
      <![CDATA[constant playerstate PLAYER_STATE_RESOURCE_GOLD             = ConvertPlayerState(1)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_RESOURCE_LUMBER" Type="playerstate" Value="ConvertPlayerState(2)">
      <![CDATA[constant playerstate PLAYER_STATE_RESOURCE_LUMBER           = ConvertPlayerState(2)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_RESOURCE_HERO_TOKENS" Type="playerstate" Value="ConvertPlayerState(3)">
      <![CDATA[constant playerstate PLAYER_STATE_RESOURCE_HERO_TOKENS      = ConvertPlayerState(3)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_RESOURCE_FOOD_CAP" Type="playerstate" Value="ConvertPlayerState(4)">
      <![CDATA[constant playerstate PLAYER_STATE_RESOURCE_FOOD_CAP         = ConvertPlayerState(4)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_RESOURCE_FOOD_USED" Type="playerstate" Value="ConvertPlayerState(5)">
      <![CDATA[constant playerstate PLAYER_STATE_RESOURCE_FOOD_USED        = ConvertPlayerState(5)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_FOOD_CAP_CEILING" Type="playerstate" Value="ConvertPlayerState(6)">
      <![CDATA[constant playerstate PLAYER_STATE_FOOD_CAP_CEILING          = ConvertPlayerState(6)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_GIVES_BOUNTY" Type="playerstate" Value="ConvertPlayerState(7)">
      <![CDATA[constant playerstate PLAYER_STATE_GIVES_BOUNTY              = ConvertPlayerState(7)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_ALLIED_VICTORY" Type="playerstate" Value="ConvertPlayerState(8)">
      <![CDATA[constant playerstate PLAYER_STATE_ALLIED_VICTORY            = ConvertPlayerState(8)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_PLACED" Type="playerstate" Value="ConvertPlayerState(9)">
      <![CDATA[constant playerstate PLAYER_STATE_PLACED                    = ConvertPlayerState(9)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_OBSERVER_ON_DEATH" Type="playerstate" Value="ConvertPlayerState(10)">
      <![CDATA[constant playerstate PLAYER_STATE_OBSERVER_ON_DEATH         = ConvertPlayerState(10)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_OBSERVER" Type="playerstate" Value="ConvertPlayerState(11)">
      <![CDATA[constant playerstate PLAYER_STATE_OBSERVER                  = ConvertPlayerState(11)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_UNFOLLOWABLE" Type="playerstate" Value="ConvertPlayerState(12)">
      <![CDATA[constant playerstate PLAYER_STATE_UNFOLLOWABLE              = ConvertPlayerState(12)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_GOLD_UPKEEP_RATE" Type="playerstate" Value="ConvertPlayerState(13)">
      <![CDATA[constant playerstate PLAYER_STATE_GOLD_UPKEEP_RATE          = ConvertPlayerState(13)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_LUMBER_UPKEEP_RATE" Type="playerstate" Value="ConvertPlayerState(14)">
      <![CDATA[constant playerstate PLAYER_STATE_LUMBER_UPKEEP_RATE        = ConvertPlayerState(14)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_GOLD_GATHERED" Type="playerstate" Value="ConvertPlayerState(15)">
      <![CDATA[constant playerstate PLAYER_STATE_GOLD_GATHERED             = ConvertPlayerState(15)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_LUMBER_GATHERED" Type="playerstate" Value="ConvertPlayerState(16)">
      <![CDATA[constant playerstate PLAYER_STATE_LUMBER_GATHERED           = ConvertPlayerState(16)]]>
    </Variable>

    <Variable Name="PLAYER_STATE_NO_CREEP_SLEEP" Type="playerstate" Value="ConvertPlayerState(25)">
      <![CDATA[constant playerstate PLAYER_STATE_NO_CREEP_SLEEP            = ConvertPlayerState(25)]]>
    </Variable>

    <Variable Name="UNIT_STATE_LIFE" Type="unitstate" Value="ConvertUnitState(0)">
      <![CDATA[constant unitstate UNIT_STATE_LIFE                          = ConvertUnitState(0)]]>
    </Variable>

    <Variable Name="UNIT_STATE_MAX_LIFE" Type="unitstate" Value="ConvertUnitState(1)">
      <![CDATA[constant unitstate UNIT_STATE_MAX_LIFE                      = ConvertUnitState(1)]]>
    </Variable>

    <Variable Name="UNIT_STATE_MANA" Type="unitstate" Value="ConvertUnitState(2)">
      <![CDATA[constant unitstate UNIT_STATE_MANA                          = ConvertUnitState(2)]]>
    </Variable>

    <Variable Name="UNIT_STATE_MAX_MANA" Type="unitstate" Value="ConvertUnitState(3)">
      <![CDATA[constant unitstate UNIT_STATE_MAX_MANA                      = ConvertUnitState(3)]]>
    </Variable>

    <Variable Name="AI_DIFFICULTY_NEWBIE" Type="aidifficulty" Value="ConvertAIDifficulty(0)">
      <![CDATA[constant aidifficulty AI_DIFFICULTY_NEWBIE                  = ConvertAIDifficulty(0)]]>
    </Variable>

    <Variable Name="AI_DIFFICULTY_NORMAL" Type="aidifficulty" Value="ConvertAIDifficulty(1)">
      <![CDATA[constant aidifficulty AI_DIFFICULTY_NORMAL                  = ConvertAIDifficulty(1)]]>
    </Variable>

    <Variable Name="AI_DIFFICULTY_INSANE" Type="aidifficulty" Value="ConvertAIDifficulty(2)">
      <![CDATA[constant aidifficulty AI_DIFFICULTY_INSANE                  = ConvertAIDifficulty(2)]]>
    </Variable>

    <Variable Name="EVENT_GAME_VICTORY" Type="gameevent" Value="ConvertGameEvent(0)">
      <![CDATA[constant gameevent EVENT_GAME_VICTORY                       = ConvertGameEvent(0)]]>
    </Variable>

    <Variable Name="EVENT_GAME_END_LEVEL" Type="gameevent" Value="ConvertGameEvent(1)">
      <![CDATA[constant gameevent EVENT_GAME_END_LEVEL                     = ConvertGameEvent(1)]]>
    </Variable>

    <Variable Name="EVENT_GAME_VARIABLE_LIMIT" Type="gameevent" Value="ConvertGameEvent(2)">
      <![CDATA[constant gameevent EVENT_GAME_VARIABLE_LIMIT                = ConvertGameEvent(2)]]>
    </Variable>

    <Variable Name="EVENT_GAME_STATE_LIMIT" Type="gameevent" Value="ConvertGameEvent(3)">
      <![CDATA[constant gameevent EVENT_GAME_STATE_LIMIT                   = ConvertGameEvent(3)   ]]>
    </Variable>

    <Variable Name="EVENT_GAME_TIMER_EXPIRED" Type="gameevent" Value="ConvertGameEvent(4)">
      <![CDATA[constant gameevent EVENT_GAME_TIMER_EXPIRED                 = ConvertGameEvent(4)]]>
    </Variable>

    <Variable Name="EVENT_GAME_ENTER_REGION" Type="gameevent" Value="ConvertGameEvent(5)">
      <![CDATA[constant gameevent EVENT_GAME_ENTER_REGION                  = ConvertGameEvent(5)]]>
    </Variable>

    <Variable Name="EVENT_GAME_LEAVE_REGION" Type="gameevent" Value="ConvertGameEvent(6)">
      <![CDATA[constant gameevent EVENT_GAME_LEAVE_REGION                  = ConvertGameEvent(6)]]>
    </Variable>

    <Variable Name="EVENT_GAME_TRACKABLE_HIT" Type="gameevent" Value="ConvertGameEvent(7)">
      <![CDATA[constant gameevent EVENT_GAME_TRACKABLE_HIT                 = ConvertGameEvent(7)]]>
    </Variable>

    <Variable Name="EVENT_GAME_TRACKABLE_TRACK" Type="gameevent" Value="ConvertGameEvent(8)">
      <![CDATA[constant gameevent EVENT_GAME_TRACKABLE_TRACK               = ConvertGameEvent(8)]]>
    </Variable>

    <Variable Name="EVENT_GAME_SHOW_SKILL" Type="gameevent" Value="ConvertGameEvent(9)">
      <![CDATA[constant gameevent EVENT_GAME_SHOW_SKILL                    = ConvertGameEvent(9)    ]]>
    </Variable>

    <Variable Name="EVENT_GAME_BUILD_SUBMENU" Type="gameevent" Value="ConvertGameEvent(10)">
      <![CDATA[constant gameevent EVENT_GAME_BUILD_SUBMENU                 = ConvertGameEvent(10)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_STATE_LIMIT" Type="playerevent" Value="ConvertPlayerEvent(11)">
      <![CDATA[constant playerevent EVENT_PLAYER_STATE_LIMIT               = ConvertPlayerEvent(11)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ALLIANCE_CHANGED" Type="playerevent" Value="ConvertPlayerEvent(12)">
      <![CDATA[constant playerevent EVENT_PLAYER_ALLIANCE_CHANGED          = ConvertPlayerEvent(12)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_DEFEAT" Type="playerevent" Value="ConvertPlayerEvent(13)">
      <![CDATA[constant playerevent EVENT_PLAYER_DEFEAT                    = ConvertPlayerEvent(13)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_VICTORY" Type="playerevent" Value="ConvertPlayerEvent(14)">
      <![CDATA[constant playerevent EVENT_PLAYER_VICTORY                   = ConvertPlayerEvent(14)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_LEAVE" Type="playerevent" Value="ConvertPlayerEvent(15)">
      <![CDATA[constant playerevent EVENT_PLAYER_LEAVE                     = ConvertPlayerEvent(15)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_CHAT" Type="playerevent" Value="ConvertPlayerEvent(16)">
      <![CDATA[constant playerevent EVENT_PLAYER_CHAT                      = ConvertPlayerEvent(16)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_END_CINEMATIC" Type="playerevent" Value="ConvertPlayerEvent(17)">
      <![CDATA[constant playerevent EVENT_PLAYER_END_CINEMATIC             = ConvertPlayerEvent(17)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_ATTACKED" Type="playerunitevent" Value="ConvertPlayerUnitEvent(18)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_ATTACKED                 = ConvertPlayerUnitEvent(18)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_RESCUED" Type="playerunitevent" Value="ConvertPlayerUnitEvent(19)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_RESCUED                  = ConvertPlayerUnitEvent(19)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_DEATH" Type="playerunitevent" Value="ConvertPlayerUnitEvent(20)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_DEATH                    = ConvertPlayerUnitEvent(20)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_DECAY" Type="playerunitevent" Value="ConvertPlayerUnitEvent(21)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_DECAY                    = ConvertPlayerUnitEvent(21)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_DETECTED" Type="playerunitevent" Value="ConvertPlayerUnitEvent(22)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_DETECTED                 = ConvertPlayerUnitEvent(22)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_HIDDEN" Type="playerunitevent" Value="ConvertPlayerUnitEvent(23)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_HIDDEN                   = ConvertPlayerUnitEvent(23)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SELECTED" Type="playerunitevent" Value="ConvertPlayerUnitEvent(24)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_SELECTED                 = ConvertPlayerUnitEvent(24)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_DESELECTED" Type="playerunitevent" Value="ConvertPlayerUnitEvent(25)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_DESELECTED               = ConvertPlayerUnitEvent(25)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_CONSTRUCT_START" Type="playerunitevent" Value="ConvertPlayerUnitEvent(26)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_CONSTRUCT_START          = ConvertPlayerUnitEvent(26)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_CONSTRUCT_CANCEL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(27)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_CONSTRUCT_CANCEL         = ConvertPlayerUnitEvent(27)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_CONSTRUCT_FINISH" Type="playerunitevent" Value="ConvertPlayerUnitEvent(28)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_CONSTRUCT_FINISH         = ConvertPlayerUnitEvent(28)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_UPGRADE_START" Type="playerunitevent" Value="ConvertPlayerUnitEvent(29)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_UPGRADE_START            = ConvertPlayerUnitEvent(29)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_UPGRADE_CANCEL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(30)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_UPGRADE_CANCEL           = ConvertPlayerUnitEvent(30)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_UPGRADE_FINISH" Type="playerunitevent" Value="ConvertPlayerUnitEvent(31)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_UPGRADE_FINISH           = ConvertPlayerUnitEvent(31)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_TRAIN_START" Type="playerunitevent" Value="ConvertPlayerUnitEvent(32)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_TRAIN_START              = ConvertPlayerUnitEvent(32)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_TRAIN_CANCEL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(33)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_TRAIN_CANCEL             = ConvertPlayerUnitEvent(33)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_TRAIN_FINISH" Type="playerunitevent" Value="ConvertPlayerUnitEvent(34)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_TRAIN_FINISH             = ConvertPlayerUnitEvent(34)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_RESEARCH_START" Type="playerunitevent" Value="ConvertPlayerUnitEvent(35)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_RESEARCH_START           = ConvertPlayerUnitEvent(35)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_RESEARCH_CANCEL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(36)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_RESEARCH_CANCEL          = ConvertPlayerUnitEvent(36)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_RESEARCH_FINISH" Type="playerunitevent" Value="ConvertPlayerUnitEvent(37)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_RESEARCH_FINISH          = ConvertPlayerUnitEvent(37)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_ISSUED_ORDER" Type="playerunitevent" Value="ConvertPlayerUnitEvent(38)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_ISSUED_ORDER             = ConvertPlayerUnitEvent(38)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER" Type="playerunitevent" Value="ConvertPlayerUnitEvent(39)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER       = ConvertPlayerUnitEvent(39)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER" Type="playerunitevent" Value="ConvertPlayerUnitEvent(40)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER      = ConvertPlayerUnitEvent(40)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER" Type="playerunitevent" Value="ConvertPlayerUnitEvent(40)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_ISSUED_UNIT_ORDER        = ConvertPlayerUnitEvent(40)    // for compat]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_HERO_LEVEL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(41)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_HERO_LEVEL                    = ConvertPlayerUnitEvent(41)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_HERO_SKILL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(42)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_HERO_SKILL                    = ConvertPlayerUnitEvent(42)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_HERO_REVIVABLE" Type="playerunitevent" Value="ConvertPlayerUnitEvent(43)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_HERO_REVIVABLE                = ConvertPlayerUnitEvent(43)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_HERO_REVIVE_START" Type="playerunitevent" Value="ConvertPlayerUnitEvent(44)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_HERO_REVIVE_START             = ConvertPlayerUnitEvent(44)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_HERO_REVIVE_CANCEL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(45)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_HERO_REVIVE_CANCEL            = ConvertPlayerUnitEvent(45)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_HERO_REVIVE_FINISH" Type="playerunitevent" Value="ConvertPlayerUnitEvent(46)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_HERO_REVIVE_FINISH            = ConvertPlayerUnitEvent(46)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SUMMON" Type="playerunitevent" Value="ConvertPlayerUnitEvent(47)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_SUMMON                   = ConvertPlayerUnitEvent(47)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_DROP_ITEM" Type="playerunitevent" Value="ConvertPlayerUnitEvent(48)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_DROP_ITEM                = ConvertPlayerUnitEvent(48)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_PICKUP_ITEM" Type="playerunitevent" Value="ConvertPlayerUnitEvent(49)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_PICKUP_ITEM              = ConvertPlayerUnitEvent(49)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_USE_ITEM" Type="playerunitevent" Value="ConvertPlayerUnitEvent(50)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_USE_ITEM                 = ConvertPlayerUnitEvent(50)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_LOADED" Type="playerunitevent" Value="ConvertPlayerUnitEvent(51)">
      <![CDATA[constant playerunitevent EVENT_PLAYER_UNIT_LOADED                   = ConvertPlayerUnitEvent(51)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_DAMAGED" Type="unitevent" Value="ConvertUnitEvent(52)">
      <![CDATA[constant unitevent EVENT_UNIT_DAMAGED                               = ConvertUnitEvent(52)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_DEATH" Type="unitevent" Value="ConvertUnitEvent(53)">
      <![CDATA[constant unitevent EVENT_UNIT_DEATH                                 = ConvertUnitEvent(53)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_DECAY" Type="unitevent" Value="ConvertUnitEvent(54)">
      <![CDATA[constant unitevent EVENT_UNIT_DECAY                                 = ConvertUnitEvent(54)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_DETECTED" Type="unitevent" Value="ConvertUnitEvent(55)">
      <![CDATA[constant unitevent EVENT_UNIT_DETECTED                              = ConvertUnitEvent(55)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_HIDDEN" Type="unitevent" Value="ConvertUnitEvent(56)">
      <![CDATA[constant unitevent EVENT_UNIT_HIDDEN                                = ConvertUnitEvent(56)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SELECTED" Type="unitevent" Value="ConvertUnitEvent(57)">
      <![CDATA[constant unitevent EVENT_UNIT_SELECTED                              = ConvertUnitEvent(57)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_DESELECTED" Type="unitevent" Value="ConvertUnitEvent(58)">
      <![CDATA[constant unitevent EVENT_UNIT_DESELECTED                            = ConvertUnitEvent(58)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_STATE_LIMIT" Type="unitevent" Value="ConvertUnitEvent(59)">
      <![CDATA[constant unitevent EVENT_UNIT_STATE_LIMIT                           = ConvertUnitEvent(59)                                                                        ]]>
    </Variable>

    <Variable Name="EVENT_UNIT_ACQUIRED_TARGET" Type="unitevent" Value="ConvertUnitEvent(60)">
      <![CDATA[constant unitevent EVENT_UNIT_ACQUIRED_TARGET                       = ConvertUnitEvent(60)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_TARGET_IN_RANGE" Type="unitevent" Value="ConvertUnitEvent(61)">
      <![CDATA[constant unitevent EVENT_UNIT_TARGET_IN_RANGE                       = ConvertUnitEvent(61)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_ATTACKED" Type="unitevent" Value="ConvertUnitEvent(62)">
      <![CDATA[constant unitevent EVENT_UNIT_ATTACKED                              = ConvertUnitEvent(62)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_RESCUED" Type="unitevent" Value="ConvertUnitEvent(63)">
      <![CDATA[constant unitevent EVENT_UNIT_RESCUED                               = ConvertUnitEvent(63)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_CONSTRUCT_CANCEL" Type="unitevent" Value="ConvertUnitEvent(64)">
      <![CDATA[constant unitevent EVENT_UNIT_CONSTRUCT_CANCEL                      = ConvertUnitEvent(64)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_CONSTRUCT_FINISH" Type="unitevent" Value="ConvertUnitEvent(65)">
      <![CDATA[constant unitevent EVENT_UNIT_CONSTRUCT_FINISH                      = ConvertUnitEvent(65)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_UPGRADE_START" Type="unitevent" Value="ConvertUnitEvent(66)">
      <![CDATA[constant unitevent EVENT_UNIT_UPGRADE_START                         = ConvertUnitEvent(66)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_UPGRADE_CANCEL" Type="unitevent" Value="ConvertUnitEvent(67)">
      <![CDATA[constant unitevent EVENT_UNIT_UPGRADE_CANCEL                        = ConvertUnitEvent(67)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_UPGRADE_FINISH" Type="unitevent" Value="ConvertUnitEvent(68)">
      <![CDATA[constant unitevent EVENT_UNIT_UPGRADE_FINISH                        = ConvertUnitEvent(68)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_TRAIN_START" Type="unitevent" Value="ConvertUnitEvent(69)">
      <![CDATA[constant unitevent EVENT_UNIT_TRAIN_START                           = ConvertUnitEvent(69)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_TRAIN_CANCEL" Type="unitevent" Value="ConvertUnitEvent(70)">
      <![CDATA[constant unitevent EVENT_UNIT_TRAIN_CANCEL                          = ConvertUnitEvent(70)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_TRAIN_FINISH" Type="unitevent" Value="ConvertUnitEvent(71)">
      <![CDATA[constant unitevent EVENT_UNIT_TRAIN_FINISH                          = ConvertUnitEvent(71)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_RESEARCH_START" Type="unitevent" Value="ConvertUnitEvent(72)">
      <![CDATA[constant unitevent EVENT_UNIT_RESEARCH_START                        = ConvertUnitEvent(72)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_RESEARCH_CANCEL" Type="unitevent" Value="ConvertUnitEvent(73)">
      <![CDATA[constant unitevent EVENT_UNIT_RESEARCH_CANCEL                       = ConvertUnitEvent(73)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_RESEARCH_FINISH" Type="unitevent" Value="ConvertUnitEvent(74)">
      <![CDATA[constant unitevent EVENT_UNIT_RESEARCH_FINISH                       = ConvertUnitEvent(74)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_ISSUED_ORDER" Type="unitevent" Value="ConvertUnitEvent(75)">
      <![CDATA[constant unitevent EVENT_UNIT_ISSUED_ORDER                          = ConvertUnitEvent(75)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_ISSUED_POINT_ORDER" Type="unitevent" Value="ConvertUnitEvent(76)">
      <![CDATA[constant unitevent EVENT_UNIT_ISSUED_POINT_ORDER                    = ConvertUnitEvent(76)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_ISSUED_TARGET_ORDER" Type="unitevent" Value="ConvertUnitEvent(77)">
      <![CDATA[constant unitevent EVENT_UNIT_ISSUED_TARGET_ORDER                   = ConvertUnitEvent(77)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_HERO_LEVEL" Type="unitevent" Value="ConvertUnitEvent(78)">
      <![CDATA[constant unitevent EVENT_UNIT_HERO_LEVEL                            = ConvertUnitEvent(78)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_HERO_SKILL" Type="unitevent" Value="ConvertUnitEvent(79)">
      <![CDATA[constant unitevent EVENT_UNIT_HERO_SKILL                            = ConvertUnitEvent(79)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_HERO_REVIVABLE" Type="unitevent" Value="ConvertUnitEvent(80)">
      <![CDATA[constant unitevent EVENT_UNIT_HERO_REVIVABLE                        = ConvertUnitEvent(80)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_HERO_REVIVE_START" Type="unitevent" Value="ConvertUnitEvent(81)">
      <![CDATA[constant unitevent EVENT_UNIT_HERO_REVIVE_START                     = ConvertUnitEvent(81)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_HERO_REVIVE_CANCEL" Type="unitevent" Value="ConvertUnitEvent(82)">
      <![CDATA[constant unitevent EVENT_UNIT_HERO_REVIVE_CANCEL                    = ConvertUnitEvent(82)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_HERO_REVIVE_FINISH" Type="unitevent" Value="ConvertUnitEvent(83)">
      <![CDATA[constant unitevent EVENT_UNIT_HERO_REVIVE_FINISH                    = ConvertUnitEvent(83)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SUMMON" Type="unitevent" Value="ConvertUnitEvent(84)">
      <![CDATA[constant unitevent EVENT_UNIT_SUMMON                                = ConvertUnitEvent(84)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_DROP_ITEM" Type="unitevent" Value="ConvertUnitEvent(85)">
      <![CDATA[constant unitevent EVENT_UNIT_DROP_ITEM                             = ConvertUnitEvent(85)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_PICKUP_ITEM" Type="unitevent" Value="ConvertUnitEvent(86)">
      <![CDATA[constant unitevent EVENT_UNIT_PICKUP_ITEM                           = ConvertUnitEvent(86)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_USE_ITEM" Type="unitevent" Value="ConvertUnitEvent(87)">
      <![CDATA[constant unitevent EVENT_UNIT_USE_ITEM                              = ConvertUnitEvent(87)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_LOADED" Type="unitevent" Value="ConvertUnitEvent(88)">
      <![CDATA[constant unitevent EVENT_UNIT_LOADED                                = ConvertUnitEvent(88)]]>
    </Variable>

    <Variable Name="EVENT_WIDGET_DEATH" Type="widgetevent" Value="ConvertWidgetEvent(89)">
      <![CDATA[constant widgetevent EVENT_WIDGET_DEATH                             = ConvertWidgetEvent(89)]]>
    </Variable>

    <Variable Name="EVENT_DIALOG_BUTTON_CLICK" Type="dialogevent" Value="ConvertDialogEvent(90)">
      <![CDATA[constant dialogevent EVENT_DIALOG_BUTTON_CLICK                      = ConvertDialogEvent(90)]]>
    </Variable>

    <Variable Name="EVENT_DIALOG_CLICK" Type="dialogevent" Value="ConvertDialogEvent(91)">
      <![CDATA[constant dialogevent EVENT_DIALOG_CLICK                             = ConvertDialogEvent(91)]]>
    </Variable>

    <Variable Name="EVENT_GAME_LOADED" Type="gameevent" Value="ConvertGameEvent(256)">
      <![CDATA[constant gameevent          EVENT_GAME_LOADED                       = ConvertGameEvent(256)]]>
    </Variable>

    <Variable Name="EVENT_GAME_TOURNAMENT_FINISH_SOON" Type="gameevent" Value="ConvertGameEvent(257)">
      <![CDATA[constant gameevent          EVENT_GAME_TOURNAMENT_FINISH_SOON       = ConvertGameEvent(257)]]>
    </Variable>

    <Variable Name="EVENT_GAME_TOURNAMENT_FINISH_NOW" Type="gameevent" Value="ConvertGameEvent(258)">
      <![CDATA[constant gameevent          EVENT_GAME_TOURNAMENT_FINISH_NOW        = ConvertGameEvent(258)]]>
    </Variable>

    <Variable Name="EVENT_GAME_SAVE" Type="gameevent" Value="ConvertGameEvent(259)">
      <![CDATA[constant gameevent          EVENT_GAME_SAVE                         = ConvertGameEvent(259)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ARROW_LEFT_DOWN" Type="playerevent" Value="ConvertPlayerEvent(261)">
      <![CDATA[constant playerevent        EVENT_PLAYER_ARROW_LEFT_DOWN            = ConvertPlayerEvent(261)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ARROW_LEFT_UP" Type="playerevent" Value="ConvertPlayerEvent(262)">
      <![CDATA[constant playerevent        EVENT_PLAYER_ARROW_LEFT_UP              = ConvertPlayerEvent(262)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ARROW_RIGHT_DOWN" Type="playerevent" Value="ConvertPlayerEvent(263)">
      <![CDATA[constant playerevent        EVENT_PLAYER_ARROW_RIGHT_DOWN           = ConvertPlayerEvent(263)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ARROW_RIGHT_UP" Type="playerevent" Value="ConvertPlayerEvent(264)">
      <![CDATA[constant playerevent        EVENT_PLAYER_ARROW_RIGHT_UP             = ConvertPlayerEvent(264)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ARROW_DOWN_DOWN" Type="playerevent" Value="ConvertPlayerEvent(265)">
      <![CDATA[constant playerevent        EVENT_PLAYER_ARROW_DOWN_DOWN            = ConvertPlayerEvent(265)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ARROW_DOWN_UP" Type="playerevent" Value="ConvertPlayerEvent(266)">
      <![CDATA[constant playerevent        EVENT_PLAYER_ARROW_DOWN_UP              = ConvertPlayerEvent(266)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ARROW_UP_DOWN" Type="playerevent" Value="ConvertPlayerEvent(267)">
      <![CDATA[constant playerevent        EVENT_PLAYER_ARROW_UP_DOWN              = ConvertPlayerEvent(267)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_ARROW_UP_UP" Type="playerevent" Value="ConvertPlayerEvent(268)">
      <![CDATA[constant playerevent        EVENT_PLAYER_ARROW_UP_UP                = ConvertPlayerEvent(268)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SELL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(269)">
      <![CDATA[constant playerunitevent    EVENT_PLAYER_UNIT_SELL                  = ConvertPlayerUnitEvent(269)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_CHANGE_OWNER" Type="playerunitevent" Value="ConvertPlayerUnitEvent(270)">
      <![CDATA[constant playerunitevent    EVENT_PLAYER_UNIT_CHANGE_OWNER          = ConvertPlayerUnitEvent(270)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SELL_ITEM" Type="playerunitevent" Value="ConvertPlayerUnitEvent(271)">
      <![CDATA[constant playerunitevent    EVENT_PLAYER_UNIT_SELL_ITEM             = ConvertPlayerUnitEvent(271)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SPELL_CHANNEL" Type="playerunitevent" Value="ConvertPlayerUnitEvent(272)">
      <![CDATA[constant playerunitevent    EVENT_PLAYER_UNIT_SPELL_CHANNEL         = ConvertPlayerUnitEvent(272)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SPELL_CAST" Type="playerunitevent" Value="ConvertPlayerUnitEvent(273)">
      <![CDATA[constant playerunitevent    EVENT_PLAYER_UNIT_SPELL_CAST            = ConvertPlayerUnitEvent(273)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SPELL_EFFECT" Type="playerunitevent" Value="ConvertPlayerUnitEvent(274)">
      <![CDATA[constant playerunitevent    EVENT_PLAYER_UNIT_SPELL_EFFECT          = ConvertPlayerUnitEvent(274)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SPELL_FINISH" Type="playerunitevent" Value="ConvertPlayerUnitEvent(275)">
      <![CDATA[constant playerunitevent    EVENT_PLAYER_UNIT_SPELL_FINISH          = ConvertPlayerUnitEvent(275)]]>
    </Variable>

    <Variable Name="EVENT_PLAYER_UNIT_SPELL_ENDCAST" Type="playerunitevent" Value="ConvertPlayerUnitEvent(276)">
      <![CDATA[constant playerunitevent    EVENT_PLAYER_UNIT_SPELL_ENDCAST         = ConvertPlayerUnitEvent(276)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SELL" Type="unitevent" Value="ConvertUnitEvent(286)">
      <![CDATA[constant unitevent          EVENT_UNIT_SELL                         = ConvertUnitEvent(286)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_CHANGE_OWNER" Type="unitevent" Value="ConvertUnitEvent(287)">
      <![CDATA[constant unitevent          EVENT_UNIT_CHANGE_OWNER                 = ConvertUnitEvent(287)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SELL_ITEM" Type="unitevent" Value="ConvertUnitEvent(288)">
      <![CDATA[constant unitevent          EVENT_UNIT_SELL_ITEM                    = ConvertUnitEvent(288)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SPELL_CHANNEL" Type="unitevent" Value="ConvertUnitEvent(289)">
      <![CDATA[constant unitevent          EVENT_UNIT_SPELL_CHANNEL                = ConvertUnitEvent(289)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SPELL_CAST" Type="unitevent" Value="ConvertUnitEvent(290)">
      <![CDATA[constant unitevent          EVENT_UNIT_SPELL_CAST                   = ConvertUnitEvent(290)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SPELL_EFFECT" Type="unitevent" Value="ConvertUnitEvent(291)">
      <![CDATA[constant unitevent          EVENT_UNIT_SPELL_EFFECT                 = ConvertUnitEvent(291)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SPELL_FINISH" Type="unitevent" Value="ConvertUnitEvent(292)">
      <![CDATA[constant unitevent          EVENT_UNIT_SPELL_FINISH                 = ConvertUnitEvent(292)]]>
    </Variable>

    <Variable Name="EVENT_UNIT_SPELL_ENDCAST" Type="unitevent" Value="ConvertUnitEvent(293)">
      <![CDATA[constant unitevent          EVENT_UNIT_SPELL_ENDCAST                = ConvertUnitEvent(293)]]>
    </Variable>

    <Variable Name="LESS_THAN" Type="limitop" Value="ConvertLimitOp(0)">
      <![CDATA[constant limitop LESS_THAN                              = ConvertLimitOp(0)]]>
    </Variable>

    <Variable Name="LESS_THAN_OR_EQUAL" Type="limitop" Value="ConvertLimitOp(1)">
      <![CDATA[constant limitop LESS_THAN_OR_EQUAL                     = ConvertLimitOp(1)]]>
    </Variable>

    <Variable Name="EQUAL" Type="limitop" Value="ConvertLimitOp(2)">
      <![CDATA[constant limitop EQUAL                                  = ConvertLimitOp(2)]]>
    </Variable>

    <Variable Name="GREATER_THAN_OR_EQUAL" Type="limitop" Value="ConvertLimitOp(3)">
      <![CDATA[constant limitop GREATER_THAN_OR_EQUAL                  = ConvertLimitOp(3)]]>
    </Variable>

    <Variable Name="GREATER_THAN" Type="limitop" Value="ConvertLimitOp(4)">
      <![CDATA[constant limitop GREATER_THAN                           = ConvertLimitOp(4)]]>
    </Variable>

    <Variable Name="NOT_EQUAL" Type="limitop" Value="ConvertLimitOp(5)">
      <![CDATA[constant limitop NOT_EQUAL                              = ConvertLimitOp(5)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_HERO" Type="unittype" Value="ConvertUnitType(0)">
      <![CDATA[constant unittype UNIT_TYPE_HERO                        = ConvertUnitType(0)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_DEAD" Type="unittype" Value="ConvertUnitType(1)">
      <![CDATA[constant unittype UNIT_TYPE_DEAD                        = ConvertUnitType(1)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_STRUCTURE" Type="unittype" Value="ConvertUnitType(2)">
      <![CDATA[constant unittype UNIT_TYPE_STRUCTURE                   = ConvertUnitType(2)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_FLYING" Type="unittype" Value="ConvertUnitType(3)">
      <![CDATA[constant unittype UNIT_TYPE_FLYING                      = ConvertUnitType(3)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_GROUND" Type="unittype" Value="ConvertUnitType(4)">
      <![CDATA[constant unittype UNIT_TYPE_GROUND                      = ConvertUnitType(4)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_ATTACKS_FLYING" Type="unittype" Value="ConvertUnitType(5)">
      <![CDATA[constant unittype UNIT_TYPE_ATTACKS_FLYING              = ConvertUnitType(5)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_ATTACKS_GROUND" Type="unittype" Value="ConvertUnitType(6)">
      <![CDATA[constant unittype UNIT_TYPE_ATTACKS_GROUND              = ConvertUnitType(6)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_MELEE_ATTACKER" Type="unittype" Value="ConvertUnitType(7)">
      <![CDATA[constant unittype UNIT_TYPE_MELEE_ATTACKER              = ConvertUnitType(7)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_RANGED_ATTACKER" Type="unittype" Value="ConvertUnitType(8)">
      <![CDATA[constant unittype UNIT_TYPE_RANGED_ATTACKER             = ConvertUnitType(8)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_GIANT" Type="unittype" Value="ConvertUnitType(9)">
      <![CDATA[constant unittype UNIT_TYPE_GIANT                       = ConvertUnitType(9)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_SUMMONED" Type="unittype" Value="ConvertUnitType(10)">
      <![CDATA[constant unittype UNIT_TYPE_SUMMONED                    = ConvertUnitType(10)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_STUNNED" Type="unittype" Value="ConvertUnitType(11)">
      <![CDATA[constant unittype UNIT_TYPE_STUNNED                     = ConvertUnitType(11)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_PLAGUED" Type="unittype" Value="ConvertUnitType(12)">
      <![CDATA[constant unittype UNIT_TYPE_PLAGUED                     = ConvertUnitType(12)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_SNARED" Type="unittype" Value="ConvertUnitType(13)">
      <![CDATA[constant unittype UNIT_TYPE_SNARED                      = ConvertUnitType(13)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_UNDEAD" Type="unittype" Value="ConvertUnitType(14)">
      <![CDATA[constant unittype UNIT_TYPE_UNDEAD                      = ConvertUnitType(14)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_MECHANICAL" Type="unittype" Value="ConvertUnitType(15)">
      <![CDATA[constant unittype UNIT_TYPE_MECHANICAL                  = ConvertUnitType(15)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_PEON" Type="unittype" Value="ConvertUnitType(16)">
      <![CDATA[constant unittype UNIT_TYPE_PEON                        = ConvertUnitType(16)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_SAPPER" Type="unittype" Value="ConvertUnitType(17)">
      <![CDATA[constant unittype UNIT_TYPE_SAPPER                      = ConvertUnitType(17)]]>
    </Variable>

    <Variable Name="UNIT_TYPE_TOWNHALL" Type="unittype" Value="ConvertUnitType(18)">
      <![CDATA[constant unittype UNIT_TYPE_TOWNHALL                    = ConvertUnitType(18)    ]]>
    </Variable>

    <Variable Name="UNIT_TYPE_ANCIENT" Type="unittype" Value="ConvertUnitType(19)">
      <![CDATA[constant unittype UNIT_TYPE_ANCIENT                     = ConvertUnitType(19)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_PERMANENT" Type="itemtype" Value="ConvertItemType(0)">
      <![CDATA[constant itemtype ITEM_TYPE_PERMANENT                   = ConvertItemType(0)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_CHARGED" Type="itemtype" Value="ConvertItemType(1)">
      <![CDATA[constant itemtype ITEM_TYPE_CHARGED                     = ConvertItemType(1)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_POWERUP" Type="itemtype" Value="ConvertItemType(2)">
      <![CDATA[constant itemtype ITEM_TYPE_POWERUP                     = ConvertItemType(2)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_ARTIFACT" Type="itemtype" Value="ConvertItemType(3)">
      <![CDATA[constant itemtype ITEM_TYPE_ARTIFACT                    = ConvertItemType(3)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_PURCHASABLE" Type="itemtype" Value="ConvertItemType(4)">
      <![CDATA[constant itemtype ITEM_TYPE_PURCHASABLE                 = ConvertItemType(4)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_CAMPAIGN" Type="itemtype" Value="ConvertItemType(5)">
      <![CDATA[constant itemtype ITEM_TYPE_CAMPAIGN                    = ConvertItemType(5)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_MISCELLANEOUS" Type="itemtype" Value="ConvertItemType(6)">
      <![CDATA[constant itemtype ITEM_TYPE_MISCELLANEOUS               = ConvertItemType(6)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_UNKNOWN" Type="itemtype" Value="ConvertItemType(7)">
      <![CDATA[constant itemtype ITEM_TYPE_UNKNOWN                     = ConvertItemType(7)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_ANY" Type="itemtype" Value="ConvertItemType(8)">
      <![CDATA[constant itemtype ITEM_TYPE_ANY                         = ConvertItemType(8)]]>
    </Variable>

    <Variable Name="ITEM_TYPE_TOME" Type="itemtype" Value="ConvertItemType(2)">
      <![CDATA[constant itemtype ITEM_TYPE_TOME                        = ConvertItemType(2)]]>
    </Variable>

    <Variable Name="CAMERA_FIELD_TARGET_DISTANCE" Type="camerafield" Value="ConvertCameraField(0)">
      <![CDATA[constant camerafield CAMERA_FIELD_TARGET_DISTANCE       = ConvertCameraField(0)]]>
    </Variable>

    <Variable Name="CAMERA_FIELD_FARZ" Type="camerafield" Value="ConvertCameraField(1)">
      <![CDATA[constant camerafield CAMERA_FIELD_FARZ                  = ConvertCameraField(1)]]>
    </Variable>

    <Variable Name="CAMERA_FIELD_ANGLE_OF_ATTACK" Type="camerafield" Value="ConvertCameraField(2)">
      <![CDATA[constant camerafield CAMERA_FIELD_ANGLE_OF_ATTACK       = ConvertCameraField(2)]]>
    </Variable>

    <Variable Name="CAMERA_FIELD_FIELD_OF_VIEW" Type="camerafield" Value="ConvertCameraField(3)">
      <![CDATA[constant camerafield CAMERA_FIELD_FIELD_OF_VIEW         = ConvertCameraField(3)]]>
    </Variable>

    <Variable Name="CAMERA_FIELD_ROLL" Type="camerafield" Value="ConvertCameraField(4)">
      <![CDATA[constant camerafield CAMERA_FIELD_ROLL                  = ConvertCameraField(4)]]>
    </Variable>

    <Variable Name="CAMERA_FIELD_ROTATION" Type="camerafield" Value="ConvertCameraField(5)">
      <![CDATA[constant camerafield CAMERA_FIELD_ROTATION              = ConvertCameraField(5)]]>
    </Variable>

    <Variable Name="CAMERA_FIELD_ZOFFSET" Type="camerafield" Value="ConvertCameraField(6)">
      <![CDATA[constant camerafield CAMERA_FIELD_ZOFFSET               = ConvertCameraField(6)]]>
    </Variable>

    <Variable Name="BLEND_MODE_NONE" Type="blendmode" Value="ConvertBlendMode(0)">
      <![CDATA[constant blendmode   BLEND_MODE_NONE                    = ConvertBlendMode(0)]]>
    </Variable>

    <Variable Name="BLEND_MODE_DONT_CARE" Type="blendmode" Value="ConvertBlendMode(0)">
      <![CDATA[constant blendmode   BLEND_MODE_DONT_CARE               = ConvertBlendMode(0)]]>
    </Variable>

    <Variable Name="BLEND_MODE_KEYALPHA" Type="blendmode" Value="ConvertBlendMode(1)">
      <![CDATA[constant blendmode   BLEND_MODE_KEYALPHA                = ConvertBlendMode(1)]]>
    </Variable>

    <Variable Name="BLEND_MODE_BLEND" Type="blendmode" Value="ConvertBlendMode(2)">
      <![CDATA[constant blendmode   BLEND_MODE_BLEND                   = ConvertBlendMode(2)]]>
    </Variable>

    <Variable Name="BLEND_MODE_ADDITIVE" Type="blendmode" Value="ConvertBlendMode(3)">
      <![CDATA[constant blendmode   BLEND_MODE_ADDITIVE                = ConvertBlendMode(3)]]>
    </Variable>

    <Variable Name="BLEND_MODE_MODULATE" Type="blendmode" Value="ConvertBlendMode(4)">
      <![CDATA[constant blendmode   BLEND_MODE_MODULATE                = ConvertBlendMode(4)]]>
    </Variable>

    <Variable Name="BLEND_MODE_MODULATE_2X" Type="blendmode" Value="ConvertBlendMode(5)">
      <![CDATA[constant blendmode   BLEND_MODE_MODULATE_2X             = ConvertBlendMode(5)]]>
    </Variable>

    <Variable Name="RARITY_FREQUENT" Type="raritycontrol" Value="ConvertRarityControl(0)">
      <![CDATA[constant raritycontrol  RARITY_FREQUENT                 = ConvertRarityControl(0)]]>
    </Variable>

    <Variable Name="RARITY_RARE" Type="raritycontrol" Value="ConvertRarityControl(1)">
      <![CDATA[constant raritycontrol  RARITY_RARE                     = ConvertRarityControl(1)]]>
    </Variable>

    <Variable Name="TEXMAP_FLAG_NONE" Type="texmapflags" Value="ConvertTexMapFlags(0)">
      <![CDATA[constant texmapflags    TEXMAP_FLAG_NONE                = ConvertTexMapFlags(0)]]>
    </Variable>

    <Variable Name="TEXMAP_FLAG_WRAP_U" Type="texmapflags" Value="ConvertTexMapFlags(1)">
      <![CDATA[constant texmapflags    TEXMAP_FLAG_WRAP_U              = ConvertTexMapFlags(1)]]>
    </Variable>

    <Variable Name="TEXMAP_FLAG_WRAP_V" Type="texmapflags" Value="ConvertTexMapFlags(2)">
      <![CDATA[constant texmapflags    TEXMAP_FLAG_WRAP_V              = ConvertTexMapFlags(2)]]>
    </Variable>

    <Variable Name="TEXMAP_FLAG_WRAP_UV" Type="texmapflags" Value="ConvertTexMapFlags(3)">
      <![CDATA[constant texmapflags    TEXMAP_FLAG_WRAP_UV             = ConvertTexMapFlags(3)]]>
    </Variable>

    <Variable Name="FOG_OF_WAR_MASKED" Type="fogstate" Value="ConvertFogState(1)">
      <![CDATA[constant fogstate       FOG_OF_WAR_MASKED               = ConvertFogState(1)]]>
    </Variable>

    <Variable Name="FOG_OF_WAR_FOGGED" Type="fogstate" Value="ConvertFogState(2)">
      <![CDATA[constant fogstate       FOG_OF_WAR_FOGGED               = ConvertFogState(2)]]>
    </Variable>

    <Variable Name="FOG_OF_WAR_VISIBLE" Type="fogstate" Value="ConvertFogState(4)">
      <![CDATA[constant fogstate       FOG_OF_WAR_VISIBLE              = ConvertFogState(4)]]>
    </Variable>

    <Variable Name="CAMERA_MARGIN_LEFT" Type="integer" Value="0">
      <![CDATA[constant integer        CAMERA_MARGIN_LEFT              = 0]]>
    </Variable>

    <Variable Name="CAMERA_MARGIN_RIGHT" Type="integer" Value="1">
      <![CDATA[constant integer        CAMERA_MARGIN_RIGHT             = 1]]>
    </Variable>

    <Variable Name="CAMERA_MARGIN_TOP" Type="integer" Value="2">
      <![CDATA[constant integer        CAMERA_MARGIN_TOP               = 2]]>
    </Variable>

    <Variable Name="CAMERA_MARGIN_BOTTOM" Type="integer" Value="3">
      <![CDATA[constant integer        CAMERA_MARGIN_BOTTOM            = 3]]>
    </Variable>

    <Variable Name="EFFECT_TYPE_EFFECT" Type="effecttype" Value="ConvertEffectType(0)">
      <![CDATA[constant effecttype     EFFECT_TYPE_EFFECT              = ConvertEffectType(0)]]>
    </Variable>

    <Variable Name="EFFECT_TYPE_TARGET" Type="effecttype" Value="ConvertEffectType(1)">
      <![CDATA[constant effecttype     EFFECT_TYPE_TARGET              = ConvertEffectType(1)]]>
    </Variable>

    <Variable Name="EFFECT_TYPE_CASTER" Type="effecttype" Value="ConvertEffectType(2)">
      <![CDATA[constant effecttype     EFFECT_TYPE_CASTER              = ConvertEffectType(2)]]>
    </Variable>

    <Variable Name="EFFECT_TYPE_SPECIAL" Type="effecttype" Value="ConvertEffectType(3)">
      <![CDATA[constant effecttype     EFFECT_TYPE_SPECIAL             = ConvertEffectType(3)]]>
    </Variable>

    <Native Name="ConvertRace" ReturnType="race" ArgumentList="integer i">
      <![CDATA[constant native ConvertRace                 takes integer i returns race]]>
    </Native>

    <Native Name="ConvertAllianceType" ReturnType="alliancetype" ArgumentList="integer i">
      <![CDATA[constant native ConvertAllianceType         takes integer i returns alliancetype]]>
    </Native>

    <Native Name="ConvertRacePref" ReturnType="racepreference" ArgumentList="integer i">
      <![CDATA[constant native ConvertRacePref             takes integer i returns racepreference]]>
    </Native>

    <Native Name="ConvertIGameState" ReturnType="igamestate" ArgumentList="integer i">
      <![CDATA[constant native ConvertIGameState           takes integer i returns igamestate]]>
    </Native>

    <Native Name="ConvertFGameState" ReturnType="fgamestate" ArgumentList="integer i">
      <![CDATA[constant native ConvertFGameState           takes integer i returns fgamestate]]>
    </Native>

    <Native Name="ConvertPlayerState" ReturnType="playerstate" ArgumentList="integer i">
      <![CDATA[constant native ConvertPlayerState          takes integer i returns playerstate]]>
    </Native>

    <Native Name="ConvertPlayerGameResult" ReturnType="playergameresult" ArgumentList="integer i">
      <![CDATA[constant native ConvertPlayerGameResult     takes integer i returns playergameresult]]>
    </Native>

    <Native Name="ConvertUnitState" ReturnType="unitstate" ArgumentList="integer i">
      <![CDATA[constant native ConvertUnitState            takes integer i returns unitstate]]>
    </Native>

    <Native Name="ConvertAIDifficulty" ReturnType="aidifficulty" ArgumentList="integer i">
      <![CDATA[constant native ConvertAIDifficulty         takes integer i returns aidifficulty]]>
    </Native>

    <Native Name="ConvertGameEvent" ReturnType="gameevent" ArgumentList="integer i">
      <![CDATA[constant native ConvertGameEvent            takes integer i returns gameevent]]>
    </Native>

    <Native Name="ConvertPlayerEvent" ReturnType="playerevent" ArgumentList="integer i">
      <![CDATA[constant native ConvertPlayerEvent          takes integer i returns playerevent]]>
    </Native>

    <Native Name="ConvertPlayerUnitEvent" ReturnType="playerunitevent" ArgumentList="integer i">
      <![CDATA[constant native ConvertPlayerUnitEvent      takes integer i returns playerunitevent]]>
    </Native>

    <Native Name="ConvertWidgetEvent" ReturnType="widgetevent" ArgumentList="integer i">
      <![CDATA[constant native ConvertWidgetEvent          takes integer i returns widgetevent]]>
    </Native>

    <Native Name="ConvertDialogEvent" ReturnType="dialogevent" ArgumentList="integer i">
      <![CDATA[constant native ConvertDialogEvent          takes integer i returns dialogevent]]>
    </Native>

    <Native Name="ConvertUnitEvent" ReturnType="unitevent" ArgumentList="integer i">
      <![CDATA[constant native ConvertUnitEvent            takes integer i returns unitevent]]>
    </Native>

    <Native Name="ConvertLimitOp" ReturnType="limitop" ArgumentList="integer i">
      <![CDATA[constant native ConvertLimitOp              takes integer i returns limitop]]>
    </Native>

    <Native Name="ConvertUnitType" ReturnType="unittype" ArgumentList="integer i">
      <![CDATA[constant native ConvertUnitType             takes integer i returns unittype]]>
    </Native>

    <Native Name="ConvertGameSpeed" ReturnType="gamespeed" ArgumentList="integer i">
      <![CDATA[constant native ConvertGameSpeed            takes integer i returns gamespeed]]>
    </Native>

    <Native Name="ConvertPlacement" ReturnType="placement" ArgumentList="integer i">
      <![CDATA[constant native ConvertPlacement            takes integer i returns placement]]>
    </Native>

    <Native Name="ConvertStartLocPrio" ReturnType="startlocprio" ArgumentList="integer i">
      <![CDATA[constant native ConvertStartLocPrio         takes integer i returns startlocprio]]>
    </Native>

    <Native Name="ConvertGameDifficulty" ReturnType="gamedifficulty" ArgumentList="integer i">
      <![CDATA[constant native ConvertGameDifficulty       takes integer i returns gamedifficulty]]>
    </Native>

    <Native Name="ConvertGameType" ReturnType="gametype" ArgumentList="integer i">
      <![CDATA[constant native ConvertGameType             takes integer i returns gametype]]>
    </Native>

    <Native Name="ConvertMapFlag" ReturnType="mapflag" ArgumentList="integer i">
      <![CDATA[constant native ConvertMapFlag              takes integer i returns mapflag]]>
    </Native>

    <Native Name="ConvertMapVisibility" ReturnType="mapvisibility" ArgumentList="integer i">
      <![CDATA[constant native ConvertMapVisibility        takes integer i returns mapvisibility]]>
    </Native>

    <Native Name="ConvertMapSetting" ReturnType="mapsetting" ArgumentList="integer i">
      <![CDATA[constant native ConvertMapSetting           takes integer i returns mapsetting]]>
    </Native>

    <Native Name="ConvertMapDensity" ReturnType="mapdensity" ArgumentList="integer i">
      <![CDATA[constant native ConvertMapDensity           takes integer i returns mapdensity]]>
    </Native>

    <Native Name="ConvertMapControl" ReturnType="mapcontrol" ArgumentList="integer i">
      <![CDATA[constant native ConvertMapControl           takes integer i returns mapcontrol]]>
    </Native>

    <Native Name="ConvertPlayerColor" ReturnType="playercolor" ArgumentList="integer i">
      <![CDATA[constant native ConvertPlayerColor          takes integer i returns playercolor]]>
    </Native>

    <Native Name="ConvertPlayerSlotState" ReturnType="playerslotstate" ArgumentList="integer i">
      <![CDATA[constant native ConvertPlayerSlotState      takes integer i returns playerslotstate]]>
    </Native>

    <Native Name="ConvertVolumeGroup" ReturnType="volumegroup" ArgumentList="integer i">
      <![CDATA[constant native ConvertVolumeGroup          takes integer i returns volumegroup]]>
    </Native>

    <Native Name="ConvertCameraField" ReturnType="camerafield" ArgumentList="integer i">
      <![CDATA[constant native ConvertCameraField          takes integer i returns camerafield]]>
    </Native>

    <Native Name="ConvertBlendMode" ReturnType="blendmode" ArgumentList="integer i">
      <![CDATA[constant native ConvertBlendMode            takes integer i returns blendmode]]>
    </Native>

    <Native Name="ConvertRarityControl" ReturnType="raritycontrol" ArgumentList="integer i">
      <![CDATA[constant native ConvertRarityControl        takes integer i returns raritycontrol]]>
    </Native>

    <Native Name="ConvertTexMapFlags" ReturnType="texmapflags" ArgumentList="integer i">
      <![CDATA[constant native ConvertTexMapFlags          takes integer i returns texmapflags]]>
    </Native>

    <Native Name="ConvertFogState" ReturnType="fogstate" ArgumentList="integer i">
      <![CDATA[constant native ConvertFogState             takes integer i returns fogstate]]>
    </Native>

    <Native Name="ConvertEffectType" ReturnType="effecttype" ArgumentList="integer i">
      <![CDATA[constant native ConvertEffectType           takes integer i returns effecttype]]>
    </Native>

    <Native Name="ConvertVersion" ReturnType="version" ArgumentList="integer i">
      <![CDATA[constant native ConvertVersion              takes integer i returns version]]>
    </Native>

    <Native Name="ConvertItemType" ReturnType="itemtype" ArgumentList="integer i">
      <![CDATA[constant native ConvertItemType             takes integer i returns itemtype]]>
    </Native>

    <Native Name="OrderId" ReturnType="integer" ArgumentList="string  orderIdString">
      <![CDATA[constant native OrderId                     takes string  orderIdString     returns integer]]>
    </Native>

    <Native Name="OrderId2String" ReturnType="string" ArgumentList="integer orderId">
      <![CDATA[constant native OrderId2String              takes integer orderId           returns string]]>
    </Native>

    <Native Name="UnitId" ReturnType="integer" ArgumentList="string  unitIdString">
      <![CDATA[constant native UnitId                      takes string  unitIdString      returns integer]]>
    </Native>

    <Native Name="UnitId2String" ReturnType="string" ArgumentList="integer unitId">
      <![CDATA[constant native UnitId2String               takes integer unitId            returns string]]>
    </Native>

    <Native Name="AbilityId" ReturnType="integer" ArgumentList="string  abilityIdString">
      <![CDATA[constant native AbilityId                   takes string  abilityIdString   returns integer]]>
    </Native>

    <Native Name="AbilityId2String" ReturnType="string" ArgumentList="integer abilityId">
      <![CDATA[constant native AbilityId2String            takes integer abilityId         returns string]]>
    </Native>

    <Native Name="Deg2Rad" ReturnType="real" ArgumentList="real degrees">
      <![CDATA[native Deg2Rad  takes real degrees returns real]]>
    </Native>

    <Native Name="Rad2Deg" ReturnType="real" ArgumentList="real radians">
      <![CDATA[native Rad2Deg  takes real radians returns real]]>
    </Native>

    <Native Name="Sin" ReturnType="real" ArgumentList="real radians">
      <![CDATA[native Sin      takes real radians returns real]]>
    </Native>

    <Native Name="Cos" ReturnType="real" ArgumentList="real radians">
      <![CDATA[native Cos      takes real radians returns real]]>
    </Native>

    <Native Name="Tan" ReturnType="real" ArgumentList="real radians">
      <![CDATA[native Tan      takes real radians returns real]]>
    </Native>

    <Native Name="Asin" ReturnType="real" ArgumentList="real y">
      <![CDATA[native Asin     takes real y returns real]]>
    </Native>

    <Native Name="Acos" ReturnType="real" ArgumentList="real x">
      <![CDATA[native Acos     takes real x returns real]]>
    </Native>

    <Native Name="Atan" ReturnType="real" ArgumentList="real x">
      <![CDATA[native Atan     takes real x returns real]]>
    </Native>

    <Native Name="Atan2" ReturnType="real" ArgumentList="real y, real x">
      <![CDATA[native Atan2    takes real y, real x returns real]]>
    </Native>

    <Native Name="SquareRoot" ReturnType="real" ArgumentList="real x">
      <![CDATA[native SquareRoot takes real x returns real]]>
    </Native>

    <Native Name="Pow" ReturnType="real" ArgumentList="real x, real power">
      <![CDATA[native Pow      takes real x, real power returns real]]>
    </Native>

    <Native Name="I2R" ReturnType="real" ArgumentList="integer i">
      <![CDATA[native I2R  takes integer i returns real]]>
    </Native>

    <Native Name="R2I" ReturnType="integer" ArgumentList="real r">
      <![CDATA[native R2I  takes real r returns integer]]>
    </Native>

    <Native Name="I2S" ReturnType="string" ArgumentList="integer i">
      <![CDATA[native I2S  takes integer i returns string]]>
    </Native>

    <Native Name="R2S" ReturnType="string" ArgumentList="real r">
      <![CDATA[native R2S  takes real r returns string]]>
    </Native>

    <Native Name="R2SW" ReturnType="string" ArgumentList="real r, integer width, integer precision">
      <![CDATA[native R2SW takes real r, integer width, integer precision returns string]]>
    </Native>

    <Native Name="S2I" ReturnType="integer" ArgumentList="string s">
      <![CDATA[native S2I  takes string s returns integer]]>
    </Native>

    <Native Name="S2R" ReturnType="real" ArgumentList="string s">
      <![CDATA[native S2R  takes string s returns real]]>
    </Native>

    <Native Name="SubString" ReturnType="string" ArgumentList="string source, integer start, integer end">
      <![CDATA[native SubString takes string source, integer start, integer end returns string]]>
    </Native>

    <Native Name="GetLocalizedString" ReturnType="string" ArgumentList="string source">
      <![CDATA[native GetLocalizedString takes string source returns string]]>
    </Native>

    <Native Name="GetLocalizedHotkey" ReturnType="integer" ArgumentList="string source">
      <![CDATA[native GetLocalizedHotkey takes string source returns integer]]>
    </Native>

    <Native Name="SetMapName" ReturnType="nothing" ArgumentList="string name">
      <![CDATA[native SetMapName           takes string name returns nothing]]>
    </Native>

    <Native Name="SetMapDescription" ReturnType="nothing" ArgumentList="string description">
      <![CDATA[native SetMapDescription    takes string description returns nothing]]>
    </Native>

    <Native Name="SetTeams" ReturnType="nothing" ArgumentList="integer teamcount">
      <![CDATA[native SetTeams             takes integer teamcount returns nothing]]>
    </Native>

    <Native Name="SetPlayers" ReturnType="nothing" ArgumentList="integer playercount">
      <![CDATA[native SetPlayers           takes integer playercount returns nothing]]>
    </Native>

    <Native Name="DefineStartLocation" ReturnType="nothing" ArgumentList="integer whichStartLoc, real x, real y">
      <![CDATA[native DefineStartLocation      takes integer whichStartLoc, real x, real y returns nothing]]>
    </Native>

    <Native Name="DefineStartLocationLoc" ReturnType="nothing" ArgumentList="integer whichStartLoc, location whichLocation">
      <![CDATA[native DefineStartLocationLoc   takes integer whichStartLoc, location whichLocation returns nothing]]>
    </Native>

    <Native Name="SetStartLocPrioCount" ReturnType="nothing" ArgumentList="integer whichStartLoc, integer prioSlotCount">
      <![CDATA[native SetStartLocPrioCount     takes integer whichStartLoc, integer prioSlotCount returns nothing]]>
    </Native>

    <Native Name="SetStartLocPrio" ReturnType="nothing" ArgumentList="integer whichStartLoc, integer prioSlotIndex, integer otherStartLocIndex, startlocprio priority">
      <![CDATA[native SetStartLocPrio          takes integer whichStartLoc, integer prioSlotIndex, integer otherStartLocIndex, startlocprio priority returns nothing]]>
    </Native>

    <Native Name="GetStartLocPrioSlot" ReturnType="integer" ArgumentList="integer whichStartLoc, integer prioSlotIndex">
      <![CDATA[native GetStartLocPrioSlot      takes integer whichStartLoc, integer prioSlotIndex returns integer]]>
    </Native>

    <Native Name="GetStartLocPrio" ReturnType="startlocprio" ArgumentList="integer whichStartLoc, integer prioSlotIndex">
      <![CDATA[native GetStartLocPrio          takes integer whichStartLoc, integer prioSlotIndex returns startlocprio]]>
    </Native>

    <Native Name="SetGameTypeSupported" ReturnType="nothing" ArgumentList="gametype whichGameType, boolean value">
      <![CDATA[native SetGameTypeSupported takes gametype whichGameType, boolean value returns nothing]]>
    </Native>

    <Native Name="SetMapFlag" ReturnType="nothing" ArgumentList="mapflag whichMapFlag, boolean value">
      <![CDATA[native SetMapFlag           takes mapflag whichMapFlag, boolean value returns nothing]]>
    </Native>

    <Native Name="SetGamePlacement" ReturnType="nothing" ArgumentList="placement whichPlacementType">
      <![CDATA[native SetGamePlacement     takes placement whichPlacementType returns nothing]]>
    </Native>

    <Native Name="SetGameSpeed" ReturnType="nothing" ArgumentList="gamespeed whichspeed">
      <![CDATA[native SetGameSpeed         takes gamespeed whichspeed returns nothing]]>
    </Native>

    <Native Name="SetGameDifficulty" ReturnType="nothing" ArgumentList="gamedifficulty whichdifficulty">
      <![CDATA[native SetGameDifficulty    takes gamedifficulty whichdifficulty returns nothing]]>
    </Native>

    <Native Name="SetResourceDensity" ReturnType="nothing" ArgumentList="mapdensity whichdensity">
      <![CDATA[native SetResourceDensity   takes mapdensity whichdensity returns nothing]]>
    </Native>

    <Native Name="SetCreatureDensity" ReturnType="nothing" ArgumentList="mapdensity whichdensity">
      <![CDATA[native SetCreatureDensity   takes mapdensity whichdensity returns nothing]]>
    </Native>

    <Native Name="GetTeams" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[native GetTeams             takes nothing returns integer]]>
    </Native>

    <Native Name="GetPlayers" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[native GetPlayers           takes nothing returns integer]]>
    </Native>

    <Native Name="IsGameTypeSupported" ReturnType="boolean" ArgumentList="gametype whichGameType">
      <![CDATA[native IsGameTypeSupported  takes gametype whichGameType returns boolean]]>
    </Native>

    <Native Name="GetGameTypeSelected" ReturnType="gametype" ArgumentList="nothing">
      <![CDATA[native GetGameTypeSelected  takes nothing returns gametype]]>
    </Native>

    <Native Name="IsMapFlagSet" ReturnType="boolean" ArgumentList="mapflag whichMapFlag">
      <![CDATA[native IsMapFlagSet         takes mapflag whichMapFlag returns boolean]]>
    </Native>

    <Native Name="GetGamePlacement" ReturnType="placement" ArgumentList="nothing">
      <![CDATA[constant native GetGamePlacement     takes nothing returns placement]]>
    </Native>

    <Native Name="GetGameSpeed" ReturnType="gamespeed" ArgumentList="nothing">
      <![CDATA[constant native GetGameSpeed         takes nothing returns gamespeed]]>
    </Native>

    <Native Name="GetGameDifficulty" ReturnType="gamedifficulty" ArgumentList="nothing">
      <![CDATA[constant native GetGameDifficulty    takes nothing returns gamedifficulty]]>
    </Native>

    <Native Name="GetResourceDensity" ReturnType="mapdensity" ArgumentList="nothing">
      <![CDATA[constant native GetResourceDensity   takes nothing returns mapdensity]]>
    </Native>

    <Native Name="GetCreatureDensity" ReturnType="mapdensity" ArgumentList="nothing">
      <![CDATA[constant native GetCreatureDensity   takes nothing returns mapdensity]]>
    </Native>

    <Native Name="GetStartLocationX" ReturnType="real" ArgumentList="integer whichStartLocation">
      <![CDATA[constant native GetStartLocationX    takes integer whichStartLocation returns real]]>
    </Native>

    <Native Name="GetStartLocationY" ReturnType="real" ArgumentList="integer whichStartLocation">
      <![CDATA[constant native GetStartLocationY    takes integer whichStartLocation returns real]]>
    </Native>

    <Native Name="GetStartLocationLoc" ReturnType="location" ArgumentList="integer whichStartLocation">
      <![CDATA[constant native GetStartLocationLoc  takes integer whichStartLocation returns location]]>
    </Native>

    <Native Name="SetPlayerTeam" ReturnType="nothing" ArgumentList="player whichPlayer, integer whichTeam">
      <![CDATA[native SetPlayerTeam            takes player whichPlayer, integer whichTeam returns nothing]]>
    </Native>

    <Native Name="SetPlayerStartLocation" ReturnType="nothing" ArgumentList="player whichPlayer, integer startLocIndex">
      <![CDATA[native SetPlayerStartLocation   takes player whichPlayer, integer startLocIndex returns nothing]]>
    </Native>

    <Native Name="ForcePlayerStartLocation" ReturnType="nothing" ArgumentList="player whichPlayer, integer startLocIndex">
      <![CDATA[native ForcePlayerStartLocation takes player whichPlayer, integer startLocIndex returns nothing]]>
    </Native>

    <Native Name="SetPlayerColor" ReturnType="nothing" ArgumentList="player whichPlayer, playercolor color">
      <![CDATA[native SetPlayerColor           takes player whichPlayer, playercolor color returns nothing]]>
    </Native>

    <Native Name="SetPlayerAlliance" ReturnType="nothing" ArgumentList="player sourcePlayer, player otherPlayer, alliancetype whichAllianceSetting, boolean value">
      <![CDATA[native SetPlayerAlliance        takes player sourcePlayer, player otherPlayer, alliancetype whichAllianceSetting, boolean value returns nothing]]>
    </Native>

    <Native Name="SetPlayerTaxRate" ReturnType="nothing" ArgumentList="player sourcePlayer, player otherPlayer, playerstate whichResource, integer rate">
      <![CDATA[native SetPlayerTaxRate         takes player sourcePlayer, player otherPlayer, playerstate whichResource, integer rate returns nothing]]>
    </Native>

    <Native Name="SetPlayerRacePreference" ReturnType="nothing" ArgumentList="player whichPlayer, racepreference whichRacePreference">
      <![CDATA[native SetPlayerRacePreference  takes player whichPlayer, racepreference whichRacePreference returns nothing]]>
    </Native>

    <Native Name="SetPlayerRaceSelectable" ReturnType="nothing" ArgumentList="player whichPlayer, boolean value">
      <![CDATA[native SetPlayerRaceSelectable  takes player whichPlayer, boolean value returns nothing]]>
    </Native>

    <Native Name="SetPlayerController" ReturnType="nothing" ArgumentList="player whichPlayer, mapcontrol controlType">
      <![CDATA[native SetPlayerController      takes player whichPlayer, mapcontrol controlType returns nothing]]>
    </Native>

    <Native Name="SetPlayerName" ReturnType="nothing" ArgumentList="player whichPlayer, string name">
      <![CDATA[native SetPlayerName            takes player whichPlayer, string name returns nothing]]>
    </Native>

    <Native Name="SetPlayerOnScoreScreen" ReturnType="nothing" ArgumentList="player whichPlayer, boolean flag">
      <![CDATA[native SetPlayerOnScoreScreen   takes player whichPlayer, boolean flag returns nothing]]>
    </Native>

    <Native Name="GetPlayerTeam" ReturnType="integer" ArgumentList="player whichPlayer">
      <![CDATA[native GetPlayerTeam            takes player whichPlayer returns integer]]>
    </Native>

    <Native Name="GetPlayerStartLocation" ReturnType="integer" ArgumentList="player whichPlayer">
      <![CDATA[native GetPlayerStartLocation   takes player whichPlayer returns integer]]>
    </Native>

    <Native Name="GetPlayerColor" ReturnType="playercolor" ArgumentList="player whichPlayer">
      <![CDATA[native GetPlayerColor           takes player whichPlayer returns playercolor]]>
    </Native>

    <Native Name="GetPlayerSelectable" ReturnType="boolean" ArgumentList="player whichPlayer">
      <![CDATA[native GetPlayerSelectable      takes player whichPlayer returns boolean]]>
    </Native>

    <Native Name="GetPlayerController" ReturnType="mapcontrol" ArgumentList="player whichPlayer">
      <![CDATA[native GetPlayerController      takes player whichPlayer returns mapcontrol]]>
    </Native>

    <Native Name="GetPlayerSlotState" ReturnType="playerslotstate" ArgumentList="player whichPlayer">
      <![CDATA[native GetPlayerSlotState       takes player whichPlayer returns playerslotstate]]>
    </Native>

    <Native Name="GetPlayerTaxRate" ReturnType="integer" ArgumentList="player sourcePlayer, player otherPlayer, playerstate whichResource">
      <![CDATA[native GetPlayerTaxRate         takes player sourcePlayer, player otherPlayer, playerstate whichResource returns integer]]>
    </Native>

    <Native Name="IsPlayerRacePrefSet" ReturnType="boolean" ArgumentList="player whichPlayer, racepreference pref">
      <![CDATA[native IsPlayerRacePrefSet      takes player whichPlayer, racepreference pref returns boolean]]>
    </Native>

    <Native Name="GetPlayerName" ReturnType="string" ArgumentList="player whichPlayer">
      <![CDATA[native GetPlayerName            takes player whichPlayer returns string]]>
    </Native>

    <Native Name="CreateTimer" ReturnType="timer" ArgumentList="nothing">
      <![CDATA[native CreateTimer          takes nothing returns timer]]>
    </Native>

    <Native Name="DestroyTimer" ReturnType="nothing" ArgumentList="timer whichTimer">
      <![CDATA[native DestroyTimer         takes timer whichTimer returns nothing]]>
    </Native>

    <Native Name="TimerStart" ReturnType="nothing" ArgumentList="timer whichTimer, real timeout, boolean periodic, code handlerFunc">
      <![CDATA[native TimerStart           takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing]]>
    </Native>

    <Native Name="TimerGetElapsed" ReturnType="real" ArgumentList="timer whichTimer">
      <![CDATA[native TimerGetElapsed      takes timer whichTimer returns real]]>
    </Native>

    <Native Name="TimerGetRemaining" ReturnType="real" ArgumentList="timer whichTimer">
      <![CDATA[native TimerGetRemaining    takes timer whichTimer returns real]]>
    </Native>

    <Native Name="TimerGetTimeout" ReturnType="real" ArgumentList="timer whichTimer">
      <![CDATA[native TimerGetTimeout      takes timer whichTimer returns real]]>
    </Native>

    <Native Name="PauseTimer" ReturnType="nothing" ArgumentList="timer whichTimer">
      <![CDATA[native PauseTimer           takes timer whichTimer returns nothing]]>
    </Native>

    <Native Name="ResumeTimer" ReturnType="nothing" ArgumentList="timer whichTimer">
      <![CDATA[native ResumeTimer          takes timer whichTimer returns nothing]]>
    </Native>

    <Native Name="GetExpiredTimer" ReturnType="timer" ArgumentList="nothing">
      <![CDATA[native GetExpiredTimer      takes nothing returns timer]]>
    </Native>

    <Native Name="CreateGroup" ReturnType="group" ArgumentList="nothing">
      <![CDATA[native CreateGroup                          takes nothing returns group]]>
    </Native>

    <Native Name="DestroyGroup" ReturnType="nothing" ArgumentList="group whichGroup">
      <![CDATA[native DestroyGroup                         takes group whichGroup returns nothing]]>
    </Native>

    <Native Name="GroupAddUnit" ReturnType="nothing" ArgumentList="group whichGroup, unit whichUnit">
      <![CDATA[native GroupAddUnit                         takes group whichGroup, unit whichUnit returns nothing]]>
    </Native>

    <Native Name="GroupRemoveUnit" ReturnType="nothing" ArgumentList="group whichGroup, unit whichUnit">
      <![CDATA[native GroupRemoveUnit                      takes group whichGroup, unit whichUnit returns nothing]]>
    </Native>

    <Native Name="GroupClear" ReturnType="nothing" ArgumentList="group whichGroup">
      <![CDATA[native GroupClear                           takes group whichGroup returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsOfType" ReturnType="nothing" ArgumentList="group whichGroup, string unitname, boolexpr filter">
      <![CDATA[native GroupEnumUnitsOfType                 takes group whichGroup, string unitname, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsOfPlayer" ReturnType="nothing" ArgumentList="group whichGroup, player whichPlayer, boolexpr filter">
      <![CDATA[native GroupEnumUnitsOfPlayer               takes group whichGroup, player whichPlayer, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsOfTypeCounted" ReturnType="nothing" ArgumentList="group whichGroup, string unitname, boolexpr filter, integer countLimit">
      <![CDATA[native GroupEnumUnitsOfTypeCounted          takes group whichGroup, string unitname, boolexpr filter, integer countLimit returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsInRect" ReturnType="nothing" ArgumentList="group whichGroup, rect r, boolexpr filter">
      <![CDATA[native GroupEnumUnitsInRect                 takes group whichGroup, rect r, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsInRectCounted" ReturnType="nothing" ArgumentList="group whichGroup, rect r, boolexpr filter, integer countLimit">
      <![CDATA[native GroupEnumUnitsInRectCounted          takes group whichGroup, rect r, boolexpr filter, integer countLimit returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsInRange" ReturnType="nothing" ArgumentList="group whichGroup, real x, real y, real radius, boolexpr filter">
      <![CDATA[native GroupEnumUnitsInRange                takes group whichGroup, real x, real y, real radius, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsInRangeOfLoc" ReturnType="nothing" ArgumentList="group whichGroup, location whichLocation, real radius, boolexpr filter">
      <![CDATA[native GroupEnumUnitsInRangeOfLoc           takes group whichGroup, location whichLocation, real radius, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsInRangeCounted" ReturnType="nothing" ArgumentList="group whichGroup, real x, real y, real radius, boolexpr filter, integer countLimit">
      <![CDATA[native GroupEnumUnitsInRangeCounted         takes group whichGroup, real x, real y, real radius, boolexpr filter, integer countLimit returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsInRangeOfLocCounted" ReturnType="nothing" ArgumentList="group whichGroup, location whichLocation, real radius, boolexpr filter, integer countLimit">
      <![CDATA[native GroupEnumUnitsInRangeOfLocCounted    takes group whichGroup, location whichLocation, real radius, boolexpr filter, integer countLimit returns nothing]]>
    </Native>

    <Native Name="GroupEnumUnitsSelected" ReturnType="nothing" ArgumentList="group whichGroup, player whichPlayer, boolexpr filter">
      <![CDATA[native GroupEnumUnitsSelected               takes group whichGroup, player whichPlayer, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="GroupImmediateOrder" ReturnType="boolean" ArgumentList="group whichGroup, string order">
      <![CDATA[native GroupImmediateOrder                  takes group whichGroup, string order returns boolean]]>
    </Native>

    <Native Name="GroupImmediateOrderById" ReturnType="boolean" ArgumentList="group whichGroup, integer order">
      <![CDATA[native GroupImmediateOrderById              takes group whichGroup, integer order returns boolean]]>
    </Native>

    <Native Name="GroupPointOrder" ReturnType="boolean" ArgumentList="group whichGroup, string order, real x, real y">
      <![CDATA[native GroupPointOrder                      takes group whichGroup, string order, real x, real y returns boolean]]>
    </Native>

    <Native Name="GroupPointOrderLoc" ReturnType="boolean" ArgumentList="group whichGroup, string order, location whichLocation">
      <![CDATA[native GroupPointOrderLoc                   takes group whichGroup, string order, location whichLocation returns boolean]]>
    </Native>

    <Native Name="GroupPointOrderById" ReturnType="boolean" ArgumentList="group whichGroup, integer order, real x, real y">
      <![CDATA[native GroupPointOrderById                  takes group whichGroup, integer order, real x, real y returns boolean]]>
    </Native>

    <Native Name="GroupPointOrderByIdLoc" ReturnType="boolean" ArgumentList="group whichGroup, integer order, location whichLocation">
      <![CDATA[native GroupPointOrderByIdLoc               takes group whichGroup, integer order, location whichLocation returns boolean]]>
    </Native>

    <Native Name="GroupTargetOrder" ReturnType="boolean" ArgumentList="group whichGroup, string order, widget targetWidget">
      <![CDATA[native GroupTargetOrder                     takes group whichGroup, string order, widget targetWidget returns boolean]]>
    </Native>

    <Native Name="GroupTargetOrderById" ReturnType="boolean" ArgumentList="group whichGroup, integer order, widget targetWidget">
      <![CDATA[native GroupTargetOrderById                 takes group whichGroup, integer order, widget targetWidget returns boolean]]>
    </Native>

    <Native Name="ForGroup" ReturnType="nothing" ArgumentList="group whichGroup, code callback">
      <![CDATA[native ForGroup                 takes group whichGroup, code callback returns nothing]]>
    </Native>

    <Native Name="FirstOfGroup" ReturnType="unit" ArgumentList="group whichGroup">
      <![CDATA[native FirstOfGroup             takes group whichGroup returns unit]]>
    </Native>

    <Native Name="CreateForce" ReturnType="force" ArgumentList="nothing">
      <![CDATA[native CreateForce              takes nothing returns force]]>
    </Native>

    <Native Name="DestroyForce" ReturnType="nothing" ArgumentList="force whichForce">
      <![CDATA[native DestroyForce             takes force whichForce returns nothing]]>
    </Native>

    <Native Name="ForceAddPlayer" ReturnType="nothing" ArgumentList="force whichForce, player whichPlayer">
      <![CDATA[native ForceAddPlayer           takes force whichForce, player whichPlayer returns nothing]]>
    </Native>

    <Native Name="ForceRemovePlayer" ReturnType="nothing" ArgumentList="force whichForce, player whichPlayer">
      <![CDATA[native ForceRemovePlayer        takes force whichForce, player whichPlayer returns nothing]]>
    </Native>

    <Native Name="ForceClear" ReturnType="nothing" ArgumentList="force whichForce">
      <![CDATA[native ForceClear               takes force whichForce returns nothing]]>
    </Native>

    <Native Name="ForceEnumPlayers" ReturnType="nothing" ArgumentList="force whichForce, boolexpr filter">
      <![CDATA[native ForceEnumPlayers         takes force whichForce, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="ForceEnumPlayersCounted" ReturnType="nothing" ArgumentList="force whichForce, boolexpr filter, integer countLimit">
      <![CDATA[native ForceEnumPlayersCounted  takes force whichForce, boolexpr filter, integer countLimit returns nothing]]>
    </Native>

    <Native Name="ForceEnumAllies" ReturnType="nothing" ArgumentList="force whichForce, player whichPlayer, boolexpr filter">
      <![CDATA[native ForceEnumAllies          takes force whichForce, player whichPlayer, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="ForceEnumEnemies" ReturnType="nothing" ArgumentList="force whichForce, player whichPlayer, boolexpr filter">
      <![CDATA[native ForceEnumEnemies         takes force whichForce, player whichPlayer, boolexpr filter returns nothing]]>
    </Native>

    <Native Name="ForForce" ReturnType="nothing" ArgumentList="force whichForce, code callback">
      <![CDATA[native ForForce                 takes force whichForce, code callback returns nothing]]>
    </Native>

    <Native Name="Rect" ReturnType="rect" ArgumentList="real minx, real miny, real maxx, real maxy">
      <![CDATA[native Rect                     takes real minx, real miny, real maxx, real maxy returns rect]]>
    </Native>

    <Native Name="RectFromLoc" ReturnType="rect" ArgumentList="location min, location max">
      <![CDATA[native RectFromLoc              takes location min, location max returns rect]]>
    </Native>

    <Native Name="RemoveRect" ReturnType="nothing" ArgumentList="rect whichRect">
      <![CDATA[native RemoveRect               takes rect whichRect returns nothing]]>
    </Native>

    <Native Name="SetRect" ReturnType="nothing" ArgumentList="rect whichRect, real minx, real miny, real maxx, real maxy">
      <![CDATA[native SetRect                  takes rect whichRect, real minx, real miny, real maxx, real maxy returns nothing]]>
    </Native>

    <Native Name="SetRectFromLoc" ReturnType="nothing" ArgumentList="rect whichRect, location min, location max">
      <![CDATA[native SetRectFromLoc           takes rect whichRect, location min, location max returns nothing]]>
    </Native>

    <Native Name="MoveRectTo" ReturnType="nothing" ArgumentList="rect whichRect, real newCenterX, real newCenterY">
      <![CDATA[native MoveRectTo               takes rect whichRect, real newCenterX, real newCenterY returns nothing]]>
    </Native>

    <Native Name="MoveRectToLoc" ReturnType="nothing" ArgumentList="rect whichRect, location newCenterLoc">
      <![CDATA[native MoveRectToLoc            takes rect whichRect, location newCenterLoc returns nothing]]>
    </Native>

    <Native Name="GetRectCenterX" ReturnType="real" ArgumentList="rect whichRect">
      <![CDATA[native GetRectCenterX           takes rect whichRect returns real]]>
    </Native>

    <Native Name="GetRectCenterY" ReturnType="real" ArgumentList="rect whichRect">
      <![CDATA[native GetRectCenterY           takes rect whichRect returns real]]>
    </Native>

    <Native Name="GetRectMinX" ReturnType="real" ArgumentList="rect whichRect">
      <![CDATA[native GetRectMinX              takes rect whichRect returns real]]>
    </Native>

    <Native Name="GetRectMinY" ReturnType="real" ArgumentList="rect whichRect">
      <![CDATA[native GetRectMinY              takes rect whichRect returns real]]>
    </Native>

    <Native Name="GetRectMaxX" ReturnType="real" ArgumentList="rect whichRect">
      <![CDATA[native GetRectMaxX              takes rect whichRect returns real]]>
    </Native>

    <Native Name="GetRectMaxY" ReturnType="real" ArgumentList="rect whichRect">
      <![CDATA[native GetRectMaxY              takes rect whichRect returns real]]>
    </Native>

    <Native Name="CreateRegion" ReturnType="region" ArgumentList="nothing">
      <![CDATA[native CreateRegion             takes nothing returns region]]>
    </Native>

    <Native Name="RemoveRegion" ReturnType="nothing" ArgumentList="region whichRegion">
      <![CDATA[native RemoveRegion             takes region whichRegion returns nothing]]>
    </Native>

    <Native Name="RegionAddRect" ReturnType="nothing" ArgumentList="region whichRegion, rect r">
      <![CDATA[native RegionAddRect            takes region whichRegion, rect r returns nothing]]>
    </Native>

    <Native Name="RegionClearRect" ReturnType="nothing" ArgumentList="region whichRegion, rect r">
      <![CDATA[native RegionClearRect          takes region whichRegion, rect r returns nothing]]>
    </Native>

    <Native Name="RegionAddCell" ReturnType="nothing" ArgumentList="region whichRegion, real x, real y">
      <![CDATA[native RegionAddCell           takes region whichRegion, real x, real y returns nothing]]>
    </Native>

    <Native Name="RegionAddCellAtLoc" ReturnType="nothing" ArgumentList="region whichRegion, location whichLocation">
      <![CDATA[native RegionAddCellAtLoc      takes region whichRegion, location whichLocation returns nothing]]>
    </Native>

    <Native Name="RegionClearCell" ReturnType="nothing" ArgumentList="region whichRegion, real x, real y">
      <![CDATA[native RegionClearCell         takes region whichRegion, real x, real y returns nothing]]>
    </Native>

    <Native Name="RegionClearCellAtLoc" ReturnType="nothing" ArgumentList="region whichRegion, location whichLocation">
      <![CDATA[native RegionClearCellAtLoc    takes region whichRegion, location whichLocation returns nothing]]>
    </Native>

    <Native Name="Location" ReturnType="location" ArgumentList="real x, real y">
      <![CDATA[native Location                 takes real x, real y returns location]]>
    </Native>

    <Native Name="RemoveLocation" ReturnType="nothing" ArgumentList="location whichLocation">
      <![CDATA[native RemoveLocation           takes location whichLocation returns nothing]]>
    </Native>

    <Native Name="MoveLocation" ReturnType="nothing" ArgumentList="location whichLocation, real newX, real newY">
      <![CDATA[native MoveLocation             takes location whichLocation, real newX, real newY returns nothing]]>
    </Native>

    <Native Name="GetLocationX" ReturnType="real" ArgumentList="location whichLocation">
      <![CDATA[native GetLocationX             takes location whichLocation returns real]]>
    </Native>

    <Native Name="GetLocationY" ReturnType="real" ArgumentList="location whichLocation">
      <![CDATA[native GetLocationY             takes location whichLocation returns real]]>
    </Native>

    <Native Name="GetLocationZ" ReturnType="real" ArgumentList="location whichLocation">
      <![CDATA[native GetLocationZ             takes location whichLocation returns real]]>
    </Native>

    <Native Name="IsUnitInRegion" ReturnType="boolean" ArgumentList="region whichRegion, unit whichUnit">
      <![CDATA[native IsUnitInRegion               takes region whichRegion, unit whichUnit returns boolean]]>
    </Native>

    <Native Name="IsPointInRegion" ReturnType="boolean" ArgumentList="region whichRegion, real x, real y">
      <![CDATA[native IsPointInRegion              takes region whichRegion, real x, real y returns boolean]]>
    </Native>

    <Native Name="IsLocationInRegion" ReturnType="boolean" ArgumentList="region whichRegion, location whichLocation">
      <![CDATA[native IsLocationInRegion           takes region whichRegion, location whichLocation returns boolean]]>
    </Native>

    <Native Name="GetWorldBounds" ReturnType="rect" ArgumentList="nothing">
      <![CDATA[native GetWorldBounds           takes nothing returns rect]]>
    </Native>

    <Native Name="CreateTrigger" ReturnType="trigger" ArgumentList="nothing">
      <![CDATA[native CreateTrigger    takes nothing returns trigger]]>
    </Native>

    <Native Name="DestroyTrigger" ReturnType="nothing" ArgumentList="trigger whichTrigger">
      <![CDATA[native DestroyTrigger   takes trigger whichTrigger returns nothing]]>
    </Native>

    <Native Name="ResetTrigger" ReturnType="nothing" ArgumentList="trigger whichTrigger">
      <![CDATA[native ResetTrigger     takes trigger whichTrigger returns nothing]]>
    </Native>

    <Native Name="EnableTrigger" ReturnType="nothing" ArgumentList="trigger whichTrigger">
      <![CDATA[native EnableTrigger    takes trigger whichTrigger returns nothing]]>
    </Native>

    <Native Name="DisableTrigger" ReturnType="nothing" ArgumentList="trigger whichTrigger">
      <![CDATA[native DisableTrigger   takes trigger whichTrigger returns nothing]]>
    </Native>

    <Native Name="IsTriggerEnabled" ReturnType="boolean" ArgumentList="trigger whichTrigger">
      <![CDATA[native IsTriggerEnabled takes trigger whichTrigger returns boolean]]>
    </Native>

    <Native Name="TriggerWaitOnSleeps" ReturnType="nothing" ArgumentList="trigger whichTrigger, boolean flag">
      <![CDATA[native TriggerWaitOnSleeps   takes trigger whichTrigger, boolean flag returns nothing]]>
    </Native>

    <Native Name="IsTriggerWaitOnSleeps" ReturnType="boolean" ArgumentList="trigger whichTrigger">
      <![CDATA[native IsTriggerWaitOnSleeps takes trigger whichTrigger returns boolean]]>
    </Native>

    <Native Name="GetFilterUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetFilterUnit       takes nothing returns unit]]>
    </Native>

    <Native Name="GetEnumUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetEnumUnit         takes nothing returns unit]]>
    </Native>

    <Native Name="GetFilterDestructable" ReturnType="destructable" ArgumentList="nothing">
      <![CDATA[constant native GetFilterDestructable   takes nothing returns destructable]]>
    </Native>

    <Native Name="GetEnumDestructable" ReturnType="destructable" ArgumentList="nothing">
      <![CDATA[constant native GetEnumDestructable     takes nothing returns destructable]]>
    </Native>

    <Native Name="GetFilterItem" ReturnType="item" ArgumentList="nothing">
      <![CDATA[constant native GetFilterItem           takes nothing returns item]]>
    </Native>

    <Native Name="GetEnumItem" ReturnType="item" ArgumentList="nothing">
      <![CDATA[constant native GetEnumItem             takes nothing returns item]]>
    </Native>

    <Native Name="GetFilterPlayer" ReturnType="player" ArgumentList="nothing">
      <![CDATA[constant native GetFilterPlayer     takes nothing returns player]]>
    </Native>

    <Native Name="GetEnumPlayer" ReturnType="player" ArgumentList="nothing">
      <![CDATA[constant native GetEnumPlayer       takes nothing returns player]]>
    </Native>

    <Native Name="GetTriggeringTrigger" ReturnType="trigger" ArgumentList="nothing">
      <![CDATA[constant native GetTriggeringTrigger    takes nothing returns trigger]]>
    </Native>

    <Native Name="GetTriggerEventId" ReturnType="eventid" ArgumentList="nothing">
      <![CDATA[constant native GetTriggerEventId       takes nothing returns eventid]]>
    </Native>

    <Native Name="GetTriggerEvalCount" ReturnType="integer" ArgumentList="trigger whichTrigger">
      <![CDATA[constant native GetTriggerEvalCount     takes trigger whichTrigger returns integer]]>
    </Native>

    <Native Name="GetTriggerExecCount" ReturnType="integer" ArgumentList="trigger whichTrigger">
      <![CDATA[constant native GetTriggerExecCount     takes trigger whichTrigger returns integer]]>
    </Native>

    <Native Name="ExecuteFunc" ReturnType="nothing" ArgumentList="string funcName">
      <![CDATA[native ExecuteFunc          takes string funcName returns nothing]]>
    </Native>

    <Native Name="And" ReturnType="boolexpr" ArgumentList="boolexpr operandA, boolexpr operandB">
      <![CDATA[native And              takes boolexpr operandA, boolexpr operandB returns boolexpr]]>
    </Native>

    <Native Name="Or" ReturnType="boolexpr" ArgumentList="boolexpr operandA, boolexpr operandB">
      <![CDATA[native Or               takes boolexpr operandA, boolexpr operandB returns boolexpr]]>
    </Native>

    <Native Name="Not" ReturnType="boolexpr" ArgumentList="boolexpr operand">
      <![CDATA[native Not              takes boolexpr operand returns boolexpr]]>
    </Native>

    <Native Name="Condition" ReturnType="conditionfunc" ArgumentList="code func">
      <![CDATA[native Condition        takes code func returns conditionfunc]]>
    </Native>

    <Native Name="DestroyCondition" ReturnType="nothing" ArgumentList="conditionfunc c">
      <![CDATA[native DestroyCondition takes conditionfunc c returns nothing]]>
    </Native>

    <Native Name="Filter" ReturnType="filterfunc" ArgumentList="code func">
      <![CDATA[native Filter           takes code func returns filterfunc]]>
    </Native>

    <Native Name="DestroyFilter" ReturnType="nothing" ArgumentList="filterfunc f">
      <![CDATA[native DestroyFilter    takes filterfunc f returns nothing]]>
    </Native>

    <Native Name="DestroyBoolExpr" ReturnType="nothing" ArgumentList="boolexpr e">
      <![CDATA[native DestroyBoolExpr  takes boolexpr e returns nothing]]>
    </Native>

    <Native Name="TriggerRegisterVariableEvent" ReturnType="event" ArgumentList="trigger whichTrigger, string varName, limitop opcode, real limitval">
      <![CDATA[native TriggerRegisterVariableEvent takes trigger whichTrigger, string varName, limitop opcode, real limitval returns event]]>
    </Native>

    <Native Name="TriggerRegisterTimerEvent" ReturnType="event" ArgumentList="trigger whichTrigger, real timeout, boolean periodic">
      <![CDATA[native TriggerRegisterTimerEvent takes trigger whichTrigger, real timeout, boolean periodic returns event]]>
    </Native>

    <Native Name="TriggerRegisterTimerExpireEvent" ReturnType="event" ArgumentList="trigger whichTrigger, timer t">
      <![CDATA[native TriggerRegisterTimerExpireEvent takes trigger whichTrigger, timer t returns event]]>
    </Native>

    <Native Name="TriggerRegisterGameStateEvent" ReturnType="event" ArgumentList="trigger whichTrigger, gamestate whichState, limitop opcode, real limitval">
      <![CDATA[native TriggerRegisterGameStateEvent takes trigger whichTrigger, gamestate whichState, limitop opcode, real limitval returns event]]>
    </Native>

    <Native Name="TriggerRegisterDialogEvent" ReturnType="event" ArgumentList="trigger whichTrigger, dialog whichDialog">
      <![CDATA[native TriggerRegisterDialogEvent       takes trigger whichTrigger, dialog whichDialog returns event]]>
    </Native>

    <Native Name="TriggerRegisterDialogButtonEvent" ReturnType="event" ArgumentList="trigger whichTrigger, button whichButton">
      <![CDATA[native TriggerRegisterDialogButtonEvent takes trigger whichTrigger, button whichButton returns event]]>
    </Native>

    <Native Name="GetEventGameState" ReturnType="gamestate" ArgumentList="nothing">
      <![CDATA[constant native GetEventGameState takes nothing returns gamestate]]>
    </Native>

    <Native Name="TriggerRegisterGameEvent" ReturnType="event" ArgumentList="trigger whichTrigger, gameevent whichGameEvent">
      <![CDATA[native TriggerRegisterGameEvent takes trigger whichTrigger, gameevent whichGameEvent returns event]]>
    </Native>

    <Native Name="GetWinningPlayer" ReturnType="player" ArgumentList="nothing">
      <![CDATA[constant native GetWinningPlayer takes nothing returns player]]>
    </Native>

    <Native Name="TriggerRegisterEnterRegion" ReturnType="event" ArgumentList="trigger whichTrigger, region whichRegion, boolexpr filter">
      <![CDATA[native TriggerRegisterEnterRegion takes trigger whichTrigger, region whichRegion, boolexpr filter returns event]]>
    </Native>

    <Native Name="GetTriggeringRegion" ReturnType="region" ArgumentList="nothing">
      <![CDATA[constant native GetTriggeringRegion takes nothing returns region]]>
    </Native>

    <Native Name="GetEnteringUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetEnteringUnit takes nothing returns unit]]>
    </Native>

    <Native Name="TriggerRegisterLeaveRegion" ReturnType="event" ArgumentList="trigger whichTrigger, region whichRegion, boolexpr filter">
      <![CDATA[native TriggerRegisterLeaveRegion takes trigger whichTrigger, region whichRegion, boolexpr filter returns event]]>
    </Native>

    <Native Name="GetLeavingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetLeavingUnit takes nothing returns unit]]>
    </Native>

    <Native Name="TriggerRegisterTrackableHitEvent" ReturnType="event" ArgumentList="trigger whichTrigger, trackable t">
      <![CDATA[native TriggerRegisterTrackableHitEvent takes trigger whichTrigger, trackable t returns event]]>
    </Native>

    <Native Name="TriggerRegisterTrackableTrackEvent" ReturnType="event" ArgumentList="trigger whichTrigger, trackable t">
      <![CDATA[native TriggerRegisterTrackableTrackEvent takes trigger whichTrigger, trackable t returns event]]>
    </Native>

    <Native Name="GetTriggeringTrackable" ReturnType="trackable" ArgumentList="nothing">
      <![CDATA[constant native GetTriggeringTrackable takes nothing returns trackable]]>
    </Native>

    <Native Name="GetClickedButton" ReturnType="button" ArgumentList="nothing">
      <![CDATA[constant native GetClickedButton takes nothing returns button]]>
    </Native>

    <Native Name="GetClickedDialog" ReturnType="dialog" ArgumentList="nothing">
      <![CDATA[constant native GetClickedDialog    takes nothing returns dialog]]>
    </Native>

    <Native Name="GetTournamentFinishSoonTimeRemaining" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetTournamentFinishSoonTimeRemaining takes nothing returns real]]>
    </Native>

    <Native Name="GetTournamentFinishNowRule" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[constant native GetTournamentFinishNowRule takes nothing returns integer]]>
    </Native>

    <Native Name="GetTournamentFinishNowPlayer" ReturnType="player" ArgumentList="nothing">
      <![CDATA[constant native GetTournamentFinishNowPlayer takes nothing returns player]]>
    </Native>

    <Native Name="GetTournamentScore" ReturnType="integer" ArgumentList="player whichPlayer">
      <![CDATA[constant native GetTournamentScore takes player whichPlayer returns integer]]>
    </Native>

    <Native Name="GetSaveBasicFilename" ReturnType="string" ArgumentList="nothing">
      <![CDATA[constant native GetSaveBasicFilename takes nothing returns string]]>
    </Native>

    <Native Name="TriggerRegisterPlayerEvent" ReturnType="event" ArgumentList="trigger whichTrigger, player  whichPlayer, playerevent whichPlayerEvent">
      <![CDATA[native TriggerRegisterPlayerEvent takes trigger whichTrigger, player  whichPlayer, playerevent whichPlayerEvent returns event]]>
    </Native>

    <Native Name="GetTriggerPlayer" ReturnType="player" ArgumentList="nothing">
      <![CDATA[constant native GetTriggerPlayer takes nothing returns player]]>
    </Native>

    <Native Name="TriggerRegisterPlayerUnitEvent" ReturnType="event" ArgumentList="trigger whichTrigger, player whichPlayer, playerunitevent whichPlayerUnitEvent, boolexpr filter">
      <![CDATA[native TriggerRegisterPlayerUnitEvent takes trigger whichTrigger, player whichPlayer, playerunitevent whichPlayerUnitEvent, boolexpr filter returns event]]>
    </Native>

    <Native Name="GetLevelingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetLevelingUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetLearningUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetLearningUnit      takes nothing returns unit]]>
    </Native>

    <Native Name="GetLearnedSkill" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[constant native GetLearnedSkill      takes nothing returns integer]]>
    </Native>

    <Native Name="GetLearnedSkillLevel" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[constant native GetLearnedSkillLevel takes nothing returns integer]]>
    </Native>

    <Native Name="GetRevivableUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetRevivableUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetRevivingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetRevivingUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetAttacker" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetAttacker takes nothing returns unit]]>
    </Native>

    <Native Name="GetRescuer" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetRescuer  takes nothing returns unit]]>
    </Native>

    <Native Name="GetDyingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetDyingUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetKillingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetKillingUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetDecayingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetDecayingUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetConstructingStructure" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetConstructingStructure takes nothing returns unit]]>
    </Native>

    <Native Name="GetCancelledStructure" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetCancelledStructure takes nothing returns unit]]>
    </Native>

    <Native Name="GetConstructedStructure" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetConstructedStructure takes nothing returns unit]]>
    </Native>

    <Native Name="GetResearchingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetResearchingUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetResearched" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[constant native GetResearched takes nothing returns integer]]>
    </Native>

    <Native Name="GetTrainedUnitType" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[constant native GetTrainedUnitType takes nothing returns integer]]>
    </Native>

    <Native Name="GetTrainedUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetTrainedUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetDetectedUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetDetectedUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetSummoningUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetSummoningUnit    takes nothing returns unit]]>
    </Native>

    <Native Name="GetSummonedUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetSummonedUnit     takes nothing returns unit]]>
    </Native>

    <Native Name="GetTransportUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetTransportUnit    takes nothing returns unit]]>
    </Native>

    <Native Name="GetLoadedUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetLoadedUnit       takes nothing returns unit]]>
    </Native>

    <Native Name="GetSellingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetSellingUnit      takes nothing returns unit]]>
    </Native>

    <Native Name="GetSoldUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetSoldUnit         takes nothing returns unit]]>
    </Native>

    <Native Name="GetBuyingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetBuyingUnit       takes nothing returns unit]]>
    </Native>

    <Native Name="GetSoldItem" ReturnType="item" ArgumentList="nothing">
      <![CDATA[constant native GetSoldItem         takes nothing returns item]]>
    </Native>

    <Native Name="GetChangingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetChangingUnit             takes nothing returns unit]]>
    </Native>

    <Native Name="GetChangingUnitPrevOwner" ReturnType="player" ArgumentList="nothing">
      <![CDATA[constant native GetChangingUnitPrevOwner    takes nothing returns player]]>
    </Native>

    <Native Name="GetManipulatingUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetManipulatingUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetManipulatedItem" ReturnType="item" ArgumentList="nothing">
      <![CDATA[constant native GetManipulatedItem  takes nothing returns item]]>
    </Native>

    <Native Name="GetOrderedUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetOrderedUnit takes nothing returns unit]]>
    </Native>

    <Native Name="GetIssuedOrderId" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[constant native GetIssuedOrderId takes nothing returns integer]]>
    </Native>

    <Native Name="GetOrderPointX" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetOrderPointX takes nothing returns real]]>
    </Native>

    <Native Name="GetOrderPointY" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetOrderPointY takes nothing returns real]]>
    </Native>

    <Native Name="GetOrderPointLoc" ReturnType="location" ArgumentList="nothing">
      <![CDATA[constant native GetOrderPointLoc takes nothing returns location]]>
    </Native>

    <Native Name="GetOrderTarget" ReturnType="widget" ArgumentList="nothing">
      <![CDATA[constant native GetOrderTarget              takes nothing returns widget]]>
    </Native>

    <Native Name="GetOrderTargetDestructable" ReturnType="destructable" ArgumentList="nothing">
      <![CDATA[constant native GetOrderTargetDestructable  takes nothing returns destructable]]>
    </Native>

    <Native Name="GetOrderTargetItem" ReturnType="item" ArgumentList="nothing">
      <![CDATA[constant native GetOrderTargetItem          takes nothing returns item]]>
    </Native>

    <Native Name="GetOrderTargetUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetOrderTargetUnit          takes nothing returns unit]]>
    </Native>

    <Native Name="GetSpellAbilityUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetSpellAbilityUnit         takes nothing returns unit]]>
    </Native>

    <Native Name="GetSpellAbilityId" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[constant native GetSpellAbilityId           takes nothing returns integer]]>
    </Native>

    <Native Name="GetSpellAbility" ReturnType="ability" ArgumentList="nothing">
      <![CDATA[constant native GetSpellAbility             takes nothing returns ability]]>
    </Native>

    <Native Name="TriggerRegisterPlayerAllianceChange" ReturnType="event" ArgumentList="trigger whichTrigger, player whichPlayer, alliancetype whichAlliance">
      <![CDATA[native TriggerRegisterPlayerAllianceChange takes trigger whichTrigger, player whichPlayer, alliancetype whichAlliance returns event]]>
    </Native>

    <Native Name="TriggerRegisterPlayerStateEvent" ReturnType="event" ArgumentList="trigger whichTrigger, player whichPlayer, playerstate whichState, limitop opcode, real limitval">
      <![CDATA[native TriggerRegisterPlayerStateEvent takes trigger whichTrigger, player whichPlayer, playerstate whichState, limitop opcode, real limitval returns event]]>
    </Native>

    <Native Name="GetEventPlayerState" ReturnType="playerstate" ArgumentList="nothing">
      <![CDATA[constant native GetEventPlayerState takes nothing returns playerstate]]>
    </Native>

    <Native Name="TriggerRegisterPlayerChatEvent" ReturnType="event" ArgumentList="trigger whichTrigger, player whichPlayer, string chatMessageToDetect, boolean exactMatchOnly">
      <![CDATA[native TriggerRegisterPlayerChatEvent takes trigger whichTrigger, player whichPlayer, string chatMessageToDetect, boolean exactMatchOnly returns event]]>
    </Native>

    <Native Name="GetEventPlayerChatString" ReturnType="string" ArgumentList="nothing">
      <![CDATA[constant native GetEventPlayerChatString takes nothing returns string]]>
    </Native>

    <Native Name="GetEventPlayerChatStringMatched" ReturnType="string" ArgumentList="nothing">
      <![CDATA[constant native GetEventPlayerChatStringMatched takes nothing returns string]]>
    </Native>

    <Native Name="TriggerRegisterDeathEvent" ReturnType="event" ArgumentList="trigger whichTrigger, widget whichWidget">
      <![CDATA[native TriggerRegisterDeathEvent takes trigger whichTrigger, widget whichWidget returns event]]>
    </Native>

    <Native Name="GetTriggerUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetTriggerUnit takes nothing returns unit]]>
    </Native>

    <Native Name="TriggerRegisterUnitStateEvent" ReturnType="event" ArgumentList="trigger whichTrigger, unit whichUnit, unitstate whichState, limitop opcode, real limitval">
      <![CDATA[native TriggerRegisterUnitStateEvent takes trigger whichTrigger, unit whichUnit, unitstate whichState, limitop opcode, real limitval returns event]]>
    </Native>

    <Native Name="GetEventUnitState" ReturnType="unitstate" ArgumentList="nothing">
      <![CDATA[constant native GetEventUnitState takes nothing returns unitstate]]>
    </Native>

    <Native Name="TriggerRegisterUnitEvent" ReturnType="event" ArgumentList="trigger whichTrigger, unit whichUnit, unitevent whichEvent">
      <![CDATA[native TriggerRegisterUnitEvent takes trigger whichTrigger, unit whichUnit, unitevent whichEvent returns event]]>
    </Native>

    <Native Name="GetEventDamage" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetEventDamage takes nothing returns real]]>
    </Native>

    <Native Name="GetEventDetectingPlayer" ReturnType="player" ArgumentList="nothing">
      <![CDATA[constant native GetEventDetectingPlayer takes nothing returns player]]>
    </Native>

    <Native Name="TriggerRegisterFilterUnitEvent" ReturnType="event" ArgumentList="trigger whichTrigger, unit whichUnit, unitevent whichEvent, boolexpr filter">
      <![CDATA[native TriggerRegisterFilterUnitEvent takes trigger whichTrigger, unit whichUnit, unitevent whichEvent, boolexpr filter returns event]]>
    </Native>

    <Native Name="GetEventTargetUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[constant native GetEventTargetUnit takes nothing returns unit]]>
    </Native>

    <Native Name="TriggerRegisterUnitInRange" ReturnType="event" ArgumentList="trigger whichTrigger, unit whichUnit, real range, boolexpr filter">
      <![CDATA[native TriggerRegisterUnitInRange takes trigger whichTrigger, unit whichUnit, real range, boolexpr filter returns event]]>
    </Native>

    <Native Name="TriggerAddCondition" ReturnType="triggercondition" ArgumentList="trigger whichTrigger, boolexpr condition">
      <![CDATA[native TriggerAddCondition    takes trigger whichTrigger, boolexpr condition returns triggercondition]]>
    </Native>

    <Native Name="TriggerRemoveCondition" ReturnType="nothing" ArgumentList="trigger whichTrigger, triggercondition whichCondition">
      <![CDATA[native TriggerRemoveCondition takes trigger whichTrigger, triggercondition whichCondition returns nothing]]>
    </Native>

    <Native Name="TriggerClearConditions" ReturnType="nothing" ArgumentList="trigger whichTrigger">
      <![CDATA[native TriggerClearConditions takes trigger whichTrigger returns nothing]]>
    </Native>

    <Native Name="TriggerAddAction" ReturnType="triggeraction" ArgumentList="trigger whichTrigger, code actionFunc">
      <![CDATA[native TriggerAddAction     takes trigger whichTrigger, code actionFunc returns triggeraction]]>
    </Native>

    <Native Name="TriggerRemoveAction" ReturnType="nothing" ArgumentList="trigger whichTrigger, triggeraction whichAction">
      <![CDATA[native TriggerRemoveAction  takes trigger whichTrigger, triggeraction whichAction returns nothing]]>
    </Native>

    <Native Name="TriggerClearActions" ReturnType="nothing" ArgumentList="trigger whichTrigger">
      <![CDATA[native TriggerClearActions  takes trigger whichTrigger returns nothing]]>
    </Native>

    <Native Name="TriggerSleepAction" ReturnType="nothing" ArgumentList="real timeout">
      <![CDATA[native TriggerSleepAction   takes real timeout returns nothing]]>
    </Native>

    <Native Name="TriggerWaitForSound" ReturnType="nothing" ArgumentList="sound s, real offset">
      <![CDATA[native TriggerWaitForSound  takes sound s, real offset returns nothing]]>
    </Native>

    <Native Name="TriggerEvaluate" ReturnType="boolean" ArgumentList="trigger whichTrigger">
      <![CDATA[native TriggerEvaluate      takes trigger whichTrigger returns boolean]]>
    </Native>

    <Native Name="TriggerExecute" ReturnType="nothing" ArgumentList="trigger whichTrigger">
      <![CDATA[native TriggerExecute       takes trigger whichTrigger returns nothing]]>
    </Native>

    <Native Name="TriggerExecuteWait" ReturnType="nothing" ArgumentList="trigger whichTrigger">
      <![CDATA[native TriggerExecuteWait   takes trigger whichTrigger returns nothing]]>
    </Native>

    <Native Name="TriggerSyncStart" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native TriggerSyncStart     takes nothing returns nothing]]>
    </Native>

    <Native Name="TriggerSyncReady" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native TriggerSyncReady     takes nothing returns nothing]]>
    </Native>

    <Native Name="GetWidgetLife" ReturnType="real" ArgumentList="widget whichWidget">
      <![CDATA[native  GetWidgetLife   takes widget whichWidget returns real]]>
    </Native>

    <Native Name="SetWidgetLife" ReturnType="nothing" ArgumentList="widget whichWidget, real newLife">
      <![CDATA[native  SetWidgetLife   takes widget whichWidget, real newLife returns nothing]]>
    </Native>

    <Native Name="GetWidgetX" ReturnType="real" ArgumentList="widget whichWidget">
      <![CDATA[native  GetWidgetX      takes widget whichWidget returns real]]>
    </Native>

    <Native Name="GetWidgetY" ReturnType="real" ArgumentList="widget whichWidget">
      <![CDATA[native  GetWidgetY      takes widget whichWidget returns real]]>
    </Native>

    <Native Name="GetTriggerWidget" ReturnType="widget" ArgumentList="nothing">
      <![CDATA[constant native GetTriggerWidget takes nothing returns widget]]>
    </Native>

    <Native Name="CreateDestructable" ReturnType="destructable" ArgumentList="integer objectid, real x, real y, real face, real scale, integer variation">
      <![CDATA[native          CreateDestructable          takes integer objectid, real x, real y, real face, real scale, integer variation returns destructable]]>
    </Native>

    <Native Name="CreateDestructableZ" ReturnType="destructable" ArgumentList="integer objectid, real x, real y, real z, real face, real scale, integer variation">
      <![CDATA[native          CreateDestructableZ         takes integer objectid, real x, real y, real z, real face, real scale, integer variation returns destructable]]>
    </Native>

    <Native Name="CreateDeadDestructable" ReturnType="destructable" ArgumentList="integer objectid, real x, real y, real face, real scale, integer variation">
      <![CDATA[native          CreateDeadDestructable      takes integer objectid, real x, real y, real face, real scale, integer variation returns destructable]]>
    </Native>

    <Native Name="CreateDeadDestructableZ" ReturnType="destructable" ArgumentList="integer objectid, real x, real y, real z, real face, real scale, integer variation">
      <![CDATA[native          CreateDeadDestructableZ     takes integer objectid, real x, real y, real z, real face, real scale, integer variation returns destructable]]>
    </Native>

    <Native Name="RemoveDestructable" ReturnType="nothing" ArgumentList="destructable d">
      <![CDATA[native          RemoveDestructable          takes destructable d returns nothing]]>
    </Native>

    <Native Name="KillDestructable" ReturnType="nothing" ArgumentList="destructable d">
      <![CDATA[native          KillDestructable            takes destructable d returns nothing]]>
    </Native>

    <Native Name="SetDestructableInvulnerable" ReturnType="nothing" ArgumentList="destructable d, boolean flag">
      <![CDATA[native          SetDestructableInvulnerable takes destructable d, boolean flag returns nothing]]>
    </Native>

    <Native Name="IsDestructableInvulnerable" ReturnType="boolean" ArgumentList="destructable d">
      <![CDATA[native          IsDestructableInvulnerable  takes destructable d returns boolean]]>
    </Native>

    <Native Name="EnumDestructablesInRect" ReturnType="nothing" ArgumentList="rect r, boolexpr filter, code actionFunc">
      <![CDATA[native          EnumDestructablesInRect     takes rect r, boolexpr filter, code actionFunc returns nothing]]>
    </Native>

    <Native Name="GetDestructableTypeId" ReturnType="integer" ArgumentList="destructable d">
      <![CDATA[native          GetDestructableTypeId       takes destructable d returns integer]]>
    </Native>

    <Native Name="GetDestructableX" ReturnType="real" ArgumentList="destructable d">
      <![CDATA[native          GetDestructableX            takes destructable d returns real]]>
    </Native>

    <Native Name="GetDestructableY" ReturnType="real" ArgumentList="destructable d">
      <![CDATA[native          GetDestructableY            takes destructable d returns real]]>
    </Native>

    <Native Name="SetDestructableLife" ReturnType="nothing" ArgumentList="destructable d, real life">
      <![CDATA[native          SetDestructableLife         takes destructable d, real life returns nothing]]>
    </Native>

    <Native Name="GetDestructableLife" ReturnType="real" ArgumentList="destructable d">
      <![CDATA[native          GetDestructableLife         takes destructable d returns real]]>
    </Native>

    <Native Name="SetDestructableMaxLife" ReturnType="nothing" ArgumentList="destructable d, real max">
      <![CDATA[native          SetDestructableMaxLife      takes destructable d, real max returns nothing]]>
    </Native>

    <Native Name="GetDestructableMaxLife" ReturnType="real" ArgumentList="destructable d">
      <![CDATA[native          GetDestructableMaxLife      takes destructable d returns real]]>
    </Native>

    <Native Name="DestructableRestoreLife" ReturnType="nothing" ArgumentList="destructable d, real life, boolean birth">
      <![CDATA[native          DestructableRestoreLife     takes destructable d, real life, boolean birth returns nothing]]>
    </Native>

    <Native Name="QueueDestructableAnimation" ReturnType="nothing" ArgumentList="destructable d, string whichAnimation">
      <![CDATA[native          QueueDestructableAnimation  takes destructable d, string whichAnimation returns nothing]]>
    </Native>

    <Native Name="SetDestructableAnimation" ReturnType="nothing" ArgumentList="destructable d, string whichAnimation">
      <![CDATA[native          SetDestructableAnimation    takes destructable d, string whichAnimation returns nothing]]>
    </Native>

    <Native Name="SetDestructableAnimationSpeed" ReturnType="nothing" ArgumentList="destructable d, real speedFactor">
      <![CDATA[native          SetDestructableAnimationSpeed takes destructable d, real speedFactor returns nothing]]>
    </Native>

    <Native Name="ShowDestructable" ReturnType="nothing" ArgumentList="destructable d, boolean flag">
      <![CDATA[native          ShowDestructable            takes destructable d, boolean flag returns nothing]]>
    </Native>

    <Native Name="GetDestructableOccluderHeight" ReturnType="real" ArgumentList="destructable d">
      <![CDATA[native          GetDestructableOccluderHeight takes destructable d returns real]]>
    </Native>

    <Native Name="SetDestructableOccluderHeight" ReturnType="nothing" ArgumentList="destructable d, real height">
      <![CDATA[native          SetDestructableOccluderHeight takes destructable d, real height returns nothing]]>
    </Native>

    <Native Name="CreateItem" ReturnType="item" ArgumentList="integer itemid, real x, real y">
      <![CDATA[native          CreateItem      takes integer itemid, real x, real y returns item]]>
    </Native>

    <Native Name="RemoveItem" ReturnType="nothing" ArgumentList="item whichItem">
      <![CDATA[native          RemoveItem      takes item whichItem returns nothing]]>
    </Native>

    <Native Name="GetItemPlayer" ReturnType="player" ArgumentList="item whichItem">
      <![CDATA[native          GetItemPlayer   takes item whichItem returns player]]>
    </Native>

    <Native Name="GetItemTypeId" ReturnType="integer" ArgumentList="item i">
      <![CDATA[native          GetItemTypeId   takes item i returns integer]]>
    </Native>

    <Native Name="GetItemX" ReturnType="real" ArgumentList="item i">
      <![CDATA[native          GetItemX        takes item i returns real]]>
    </Native>

    <Native Name="GetItemY" ReturnType="real" ArgumentList="item i">
      <![CDATA[native          GetItemY        takes item i returns real]]>
    </Native>

    <Native Name="SetItemPosition" ReturnType="nothing" ArgumentList="item i, real x, real y">
      <![CDATA[native          SetItemPosition takes item i, real x, real y returns nothing]]>
    </Native>

    <Native Name="SetItemDropOnDeath" ReturnType="nothing" ArgumentList="item whichItem, boolean flag">
      <![CDATA[native          SetItemDropOnDeath  takes item whichItem, boolean flag returns nothing]]>
    </Native>

    <Native Name="SetItemDroppable" ReturnType="nothing" ArgumentList="item i, boolean flag">
      <![CDATA[native          SetItemDroppable takes item i, boolean flag returns nothing]]>
    </Native>

    <Native Name="SetItemPawnable" ReturnType="nothing" ArgumentList="item i, boolean flag">
      <![CDATA[native          SetItemPawnable takes item i, boolean flag returns nothing]]>
    </Native>

    <Native Name="SetItemPlayer" ReturnType="nothing" ArgumentList="item whichItem, player whichPlayer, boolean changeColor">
      <![CDATA[native          SetItemPlayer    takes item whichItem, player whichPlayer, boolean changeColor returns nothing]]>
    </Native>

    <Native Name="SetItemInvulnerable" ReturnType="nothing" ArgumentList="item whichItem, boolean flag">
      <![CDATA[native          SetItemInvulnerable takes item whichItem, boolean flag returns nothing]]>
    </Native>

    <Native Name="IsItemInvulnerable" ReturnType="boolean" ArgumentList="item whichItem">
      <![CDATA[native          IsItemInvulnerable  takes item whichItem returns boolean]]>
    </Native>

    <Native Name="SetItemVisible" ReturnType="nothing" ArgumentList="item whichItem, boolean show">
      <![CDATA[native          SetItemVisible  takes item whichItem, boolean show returns nothing]]>
    </Native>

    <Native Name="IsItemVisible" ReturnType="boolean" ArgumentList="item whichItem">
      <![CDATA[native          IsItemVisible   takes item whichItem returns boolean]]>
    </Native>

    <Native Name="IsItemOwned" ReturnType="boolean" ArgumentList="item whichItem">
      <![CDATA[native          IsItemOwned     takes item whichItem returns boolean]]>
    </Native>

    <Native Name="IsItemPowerup" ReturnType="boolean" ArgumentList="item whichItem">
      <![CDATA[native          IsItemPowerup   takes item whichItem returns boolean]]>
    </Native>

    <Native Name="IsItemSellable" ReturnType="boolean" ArgumentList="item whichItem">
      <![CDATA[native          IsItemSellable  takes item whichItem returns boolean]]>
    </Native>

    <Native Name="IsItemPawnable" ReturnType="boolean" ArgumentList="item whichItem">
      <![CDATA[native          IsItemPawnable  takes item whichItem returns boolean]]>
    </Native>

    <Native Name="IsItemIdPowerup" ReturnType="boolean" ArgumentList="integer itemId">
      <![CDATA[native          IsItemIdPowerup takes integer itemId returns boolean]]>
    </Native>

    <Native Name="IsItemIdSellable" ReturnType="boolean" ArgumentList="integer itemId">
      <![CDATA[native          IsItemIdSellable takes integer itemId returns boolean]]>
    </Native>

    <Native Name="IsItemIdPawnable" ReturnType="boolean" ArgumentList="integer itemId">
      <![CDATA[native          IsItemIdPawnable takes integer itemId returns boolean]]>
    </Native>

    <Native Name="EnumItemsInRect" ReturnType="nothing" ArgumentList="rect r, boolexpr filter, code actionFunc">
      <![CDATA[native          EnumItemsInRect     takes rect r, boolexpr filter, code actionFunc returns nothing]]>
    </Native>

    <Native Name="GetItemLevel" ReturnType="integer" ArgumentList="item whichItem">
      <![CDATA[native          GetItemLevel    takes item whichItem returns integer]]>
    </Native>

    <Native Name="GetItemType" ReturnType="itemtype" ArgumentList="item whichItem">
      <![CDATA[native          GetItemType     takes item whichItem returns itemtype]]>
    </Native>

    <Native Name="SetItemDropID" ReturnType="nothing" ArgumentList="item whichItem, integer unitId">
      <![CDATA[native          SetItemDropID   takes item whichItem, integer unitId returns nothing]]>
    </Native>

    <Native Name="CreateUnit" ReturnType="unit" ArgumentList="player id, integer unitid, real x, real y, real face">
      <![CDATA[native          CreateUnit              takes player id, integer unitid, real x, real y, real face returns unit]]>
    </Native>

    <Native Name="CreateUnitByName" ReturnType="unit" ArgumentList="player whichPlayer, string unitname, real x, real y, real face">
      <![CDATA[native          CreateUnitByName        takes player whichPlayer, string unitname, real x, real y, real face returns unit]]>
    </Native>

    <Native Name="CreateUnitAtLoc" ReturnType="unit" ArgumentList="player id, integer unitid, location whichLocation, real face">
      <![CDATA[native          CreateUnitAtLoc         takes player id, integer unitid, location whichLocation, real face returns unit]]>
    </Native>

    <Native Name="CreateUnitAtLocByName" ReturnType="unit" ArgumentList="player id, string unitname, location whichLocation, real face">
      <![CDATA[native          CreateUnitAtLocByName   takes player id, string unitname, location whichLocation, real face returns unit]]>
    </Native>

    <Native Name="CreateCorpse" ReturnType="unit" ArgumentList="player whichPlayer, integer unitid, real x, real y, real face">
      <![CDATA[native          CreateCorpse            takes player whichPlayer, integer unitid, real x, real y, real face returns unit]]>
    </Native>

    <Native Name="KillUnit" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[native          KillUnit            takes unit whichUnit returns nothing]]>
    </Native>

    <Native Name="RemoveUnit" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[native          RemoveUnit          takes unit whichUnit returns nothing]]>
    </Native>

    <Native Name="ShowUnit" ReturnType="nothing" ArgumentList="unit whichUnit, boolean show">
      <![CDATA[native          ShowUnit            takes unit whichUnit, boolean show returns nothing]]>
    </Native>

    <Native Name="SetUnitState" ReturnType="nothing" ArgumentList="unit whichUnit, unitstate whichUnitState, real newVal">
      <![CDATA[native          SetUnitState        takes unit whichUnit, unitstate whichUnitState, real newVal returns nothing]]>
    </Native>

    <Native Name="SetUnitX" ReturnType="nothing" ArgumentList="unit whichUnit, real newX">
      <![CDATA[native          SetUnitX            takes unit whichUnit, real newX returns nothing]]>
    </Native>

    <Native Name="SetUnitY" ReturnType="nothing" ArgumentList="unit whichUnit, real newY">
      <![CDATA[native          SetUnitY            takes unit whichUnit, real newY returns nothing]]>
    </Native>

    <Native Name="SetUnitPosition" ReturnType="nothing" ArgumentList="unit whichUnit, real newX, real newY">
      <![CDATA[native          SetUnitPosition     takes unit whichUnit, real newX, real newY returns nothing]]>
    </Native>

    <Native Name="SetUnitPositionLoc" ReturnType="nothing" ArgumentList="unit whichUnit, location whichLocation">
      <![CDATA[native          SetUnitPositionLoc  takes unit whichUnit, location whichLocation returns nothing]]>
    </Native>

    <Native Name="SetUnitFacing" ReturnType="nothing" ArgumentList="unit whichUnit, real facingAngle">
      <![CDATA[native          SetUnitFacing       takes unit whichUnit, real facingAngle returns nothing]]>
    </Native>

    <Native Name="SetUnitFacingTimed" ReturnType="nothing" ArgumentList="unit whichUnit, real facingAngle, real duration">
      <![CDATA[native          SetUnitFacingTimed  takes unit whichUnit, real facingAngle, real duration returns nothing]]>
    </Native>

    <Native Name="SetUnitMoveSpeed" ReturnType="nothing" ArgumentList="unit whichUnit, real newSpeed">
      <![CDATA[native          SetUnitMoveSpeed    takes unit whichUnit, real newSpeed returns nothing]]>
    </Native>

    <Native Name="SetUnitFlyHeight" ReturnType="nothing" ArgumentList="unit whichUnit, real newHeight, real rate">
      <![CDATA[native          SetUnitFlyHeight    takes unit whichUnit, real newHeight, real rate returns nothing]]>
    </Native>

    <Native Name="SetUnitTurnSpeed" ReturnType="nothing" ArgumentList="unit whichUnit, real newTurnSpeed">
      <![CDATA[native          SetUnitTurnSpeed    takes unit whichUnit, real newTurnSpeed returns nothing]]>
    </Native>

    <Native Name="SetUnitPropWindow" ReturnType="nothing" ArgumentList="unit whichUnit, real newPropWindowAngle">
      <![CDATA[native          SetUnitPropWindow   takes unit whichUnit, real newPropWindowAngle returns nothing]]>
    </Native>

    <Native Name="SetUnitAcquireRange" ReturnType="nothing" ArgumentList="unit whichUnit, real newAcquireRange">
      <![CDATA[native          SetUnitAcquireRange takes unit whichUnit, real newAcquireRange returns nothing]]>
    </Native>

    <Native Name="SetUnitCreepGuard" ReturnType="nothing" ArgumentList="unit whichUnit, boolean creepGuard">
      <![CDATA[native          SetUnitCreepGuard   takes unit whichUnit, boolean creepGuard returns nothing]]>
    </Native>

    <Native Name="GetUnitAcquireRange" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitAcquireRange     takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitTurnSpeed" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitTurnSpeed        takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitPropWindow" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitPropWindow       takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitFlyHeight" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitFlyHeight        takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitDefaultAcquireRange" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitDefaultAcquireRange      takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitDefaultTurnSpeed" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitDefaultTurnSpeed         takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitDefaultPropWindow" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitDefaultPropWindow        takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitDefaultFlyHeight" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitDefaultFlyHeight         takes unit whichUnit returns real]]>
    </Native>

    <Native Name="SetUnitOwner" ReturnType="nothing" ArgumentList="unit whichUnit, player whichPlayer, boolean changeColor">
      <![CDATA[native          SetUnitOwner        takes unit whichUnit, player whichPlayer, boolean changeColor returns nothing]]>
    </Native>

    <Native Name="SetUnitColor" ReturnType="nothing" ArgumentList="unit whichUnit, playercolor whichColor">
      <![CDATA[native          SetUnitColor        takes unit whichUnit, playercolor whichColor returns nothing]]>
    </Native>

    <Native Name="SetUnitScale" ReturnType="nothing" ArgumentList="unit whichUnit, real scaleX, real scaleY, real scaleZ">
      <![CDATA[native          SetUnitScale        takes unit whichUnit, real scaleX, real scaleY, real scaleZ returns nothing]]>
    </Native>

    <Native Name="SetUnitTimeScale" ReturnType="nothing" ArgumentList="unit whichUnit, real timeScale">
      <![CDATA[native          SetUnitTimeScale    takes unit whichUnit, real timeScale returns nothing]]>
    </Native>

    <Native Name="SetUnitBlendTime" ReturnType="nothing" ArgumentList="unit whichUnit, real blendTime">
      <![CDATA[native          SetUnitBlendTime    takes unit whichUnit, real blendTime returns nothing]]>
    </Native>

    <Native Name="SetUnitVertexColor" ReturnType="nothing" ArgumentList="unit whichUnit, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native          SetUnitVertexColor  takes unit whichUnit, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="QueueUnitAnimation" ReturnType="nothing" ArgumentList="unit whichUnit, string whichAnimation">
      <![CDATA[native          QueueUnitAnimation          takes unit whichUnit, string whichAnimation returns nothing]]>
    </Native>

    <Native Name="SetUnitAnimation" ReturnType="nothing" ArgumentList="unit whichUnit, string whichAnimation">
      <![CDATA[native          SetUnitAnimation            takes unit whichUnit, string whichAnimation returns nothing]]>
    </Native>

    <Native Name="SetUnitAnimationByIndex" ReturnType="nothing" ArgumentList="unit whichUnit, integer whichAnimation">
      <![CDATA[native          SetUnitAnimationByIndex     takes unit whichUnit, integer whichAnimation returns nothing]]>
    </Native>

    <Native Name="SetUnitAnimationWithRarity" ReturnType="nothing" ArgumentList="unit whichUnit, string whichAnimation, raritycontrol rarity">
      <![CDATA[native          SetUnitAnimationWithRarity  takes unit whichUnit, string whichAnimation, raritycontrol rarity returns nothing]]>
    </Native>

    <Native Name="AddUnitAnimationProperties" ReturnType="nothing" ArgumentList="unit whichUnit, string animProperties, boolean add">
      <![CDATA[native          AddUnitAnimationProperties  takes unit whichUnit, string animProperties, boolean add returns nothing]]>
    </Native>

    <Native Name="SetUnitLookAt" ReturnType="nothing" ArgumentList="unit whichUnit, string whichBone, unit lookAtTarget, real offsetX, real offsetY, real offsetZ">
      <![CDATA[native          SetUnitLookAt       takes unit whichUnit, string whichBone, unit lookAtTarget, real offsetX, real offsetY, real offsetZ returns nothing]]>
    </Native>

    <Native Name="ResetUnitLookAt" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[native          ResetUnitLookAt     takes unit whichUnit returns nothing]]>
    </Native>

    <Native Name="SetUnitRescuable" ReturnType="nothing" ArgumentList="unit whichUnit, player byWhichPlayer, boolean flag">
      <![CDATA[native          SetUnitRescuable    takes unit whichUnit, player byWhichPlayer, boolean flag returns nothing]]>
    </Native>

    <Native Name="SetUnitRescueRange" ReturnType="nothing" ArgumentList="unit whichUnit, real range">
      <![CDATA[native          SetUnitRescueRange  takes unit whichUnit, real range returns nothing]]>
    </Native>

    <Native Name="SetHeroStr" ReturnType="nothing" ArgumentList="unit whichHero, integer newStr, boolean permanent">
      <![CDATA[native          SetHeroStr          takes unit whichHero, integer newStr, boolean permanent returns nothing]]>
    </Native>

    <Native Name="SetHeroAgi" ReturnType="nothing" ArgumentList="unit whichHero, integer newAgi, boolean permanent">
      <![CDATA[native          SetHeroAgi          takes unit whichHero, integer newAgi, boolean permanent returns nothing]]>
    </Native>

    <Native Name="SetHeroInt" ReturnType="nothing" ArgumentList="unit whichHero, integer newInt, boolean permanent">
      <![CDATA[native          SetHeroInt          takes unit whichHero, integer newInt, boolean permanent returns nothing]]>
    </Native>

    <Native Name="GetHeroStr" ReturnType="integer" ArgumentList="unit whichHero, boolean includeBonuses">
      <![CDATA[native          GetHeroStr          takes unit whichHero, boolean includeBonuses returns integer]]>
    </Native>

    <Native Name="GetHeroAgi" ReturnType="integer" ArgumentList="unit whichHero, boolean includeBonuses">
      <![CDATA[native          GetHeroAgi          takes unit whichHero, boolean includeBonuses returns integer]]>
    </Native>

    <Native Name="GetHeroInt" ReturnType="integer" ArgumentList="unit whichHero, boolean includeBonuses">
      <![CDATA[native          GetHeroInt          takes unit whichHero, boolean includeBonuses returns integer]]>
    </Native>

    <Native Name="UnitStripHeroLevel" ReturnType="boolean" ArgumentList="unit whichHero, integer howManyLevels">
      <![CDATA[native          UnitStripHeroLevel  takes unit whichHero, integer howManyLevels returns boolean]]>
    </Native>

    <Native Name="GetHeroXP" ReturnType="integer" ArgumentList="unit whichHero">
      <![CDATA[native          GetHeroXP           takes unit whichHero returns integer]]>
    </Native>

    <Native Name="SetHeroXP" ReturnType="nothing" ArgumentList="unit whichHero, integer newXpVal,  boolean showEyeCandy">
      <![CDATA[native          SetHeroXP           takes unit whichHero, integer newXpVal,  boolean showEyeCandy returns nothing]]>
    </Native>

    <Native Name="GetHeroSkillPoints" ReturnType="integer" ArgumentList="unit whichHero">
      <![CDATA[native          GetHeroSkillPoints      takes unit whichHero returns integer]]>
    </Native>

    <Native Name="UnitModifySkillPoints" ReturnType="boolean" ArgumentList="unit whichHero, integer skillPointDelta">
      <![CDATA[native          UnitModifySkillPoints   takes unit whichHero, integer skillPointDelta returns boolean]]>
    </Native>

    <Native Name="AddHeroXP" ReturnType="nothing" ArgumentList="unit whichHero, integer xpToAdd,   boolean showEyeCandy">
      <![CDATA[native          AddHeroXP           takes unit whichHero, integer xpToAdd,   boolean showEyeCandy returns nothing]]>
    </Native>

    <Native Name="SetHeroLevel" ReturnType="nothing" ArgumentList="unit whichHero, integer level,  boolean showEyeCandy">
      <![CDATA[native          SetHeroLevel        takes unit whichHero, integer level,  boolean showEyeCandy returns nothing]]>
    </Native>

    <Native Name="GetHeroLevel" ReturnType="integer" ArgumentList="unit whichHero">
      <![CDATA[constant native GetHeroLevel        takes unit whichHero returns integer]]>
    </Native>

    <Native Name="SuspendHeroXP" ReturnType="nothing" ArgumentList="unit whichHero, boolean flag">
      <![CDATA[native          SuspendHeroXP       takes unit whichHero, boolean flag returns nothing]]>
    </Native>

    <Native Name="IsSuspendedXP" ReturnType="boolean" ArgumentList="unit whichHero">
      <![CDATA[native          IsSuspendedXP       takes unit whichHero returns boolean]]>
    </Native>

    <Native Name="SelectHeroSkill" ReturnType="nothing" ArgumentList="unit whichHero, integer abilcode">
      <![CDATA[native          SelectHeroSkill     takes unit whichHero, integer abilcode returns nothing]]>
    </Native>

    <Native Name="ReviveHero" ReturnType="boolean" ArgumentList="unit whichHero, real x, real y, boolean doEyecandy">
      <![CDATA[native          ReviveHero          takes unit whichHero, real x, real y, boolean doEyecandy returns boolean]]>
    </Native>

    <Native Name="ReviveHeroLoc" ReturnType="boolean" ArgumentList="unit whichHero, location loc, boolean doEyecandy">
      <![CDATA[native          ReviveHeroLoc       takes unit whichHero, location loc, boolean doEyecandy returns boolean]]>
    </Native>

    <Native Name="SetUnitExploded" ReturnType="nothing" ArgumentList="unit whichUnit, boolean exploded">
      <![CDATA[native          SetUnitExploded     takes unit whichUnit, boolean exploded returns nothing]]>
    </Native>

    <Native Name="SetUnitInvulnerable" ReturnType="nothing" ArgumentList="unit whichUnit, boolean flag">
      <![CDATA[native          SetUnitInvulnerable takes unit whichUnit, boolean flag returns nothing]]>
    </Native>

    <Native Name="PauseUnit" ReturnType="nothing" ArgumentList="unit whichUnit, boolean flag">
      <![CDATA[native          PauseUnit           takes unit whichUnit, boolean flag returns nothing]]>
    </Native>

    <Native Name="IsUnitPaused" ReturnType="boolean" ArgumentList="unit whichHero">
      <![CDATA[native          IsUnitPaused        takes unit whichHero returns boolean]]>
    </Native>

    <Native Name="SetUnitPathing" ReturnType="nothing" ArgumentList="unit whichUnit, boolean flag">
      <![CDATA[native          SetUnitPathing      takes unit whichUnit, boolean flag returns nothing]]>
    </Native>

    <Native Name="ClearSelection" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native          ClearSelection      takes nothing returns nothing]]>
    </Native>

    <Native Name="SelectUnit" ReturnType="nothing" ArgumentList="unit whichUnit, boolean flag">
      <![CDATA[native          SelectUnit          takes unit whichUnit, boolean flag returns nothing]]>
    </Native>

    <Native Name="GetUnitPointValue" ReturnType="integer" ArgumentList="unit whichUnit">
      <![CDATA[native          GetUnitPointValue       takes unit whichUnit returns integer]]>
    </Native>

    <Native Name="GetUnitPointValueByType" ReturnType="integer" ArgumentList="integer unitType">
      <![CDATA[native          GetUnitPointValueByType takes integer unitType returns integer]]>
    </Native>

    <Native Name="UnitAddItem" ReturnType="boolean" ArgumentList="unit whichUnit, item whichItem">
      <![CDATA[native          UnitAddItem             takes unit whichUnit, item whichItem returns boolean]]>
    </Native>

    <Native Name="UnitAddItemById" ReturnType="item" ArgumentList="unit whichUnit, integer itemId">
      <![CDATA[native          UnitAddItemById         takes unit whichUnit, integer itemId returns item]]>
    </Native>

    <Native Name="UnitAddItemToSlotById" ReturnType="boolean" ArgumentList="unit whichUnit, integer itemId, integer itemSlot">
      <![CDATA[native          UnitAddItemToSlotById   takes unit whichUnit, integer itemId, integer itemSlot returns boolean]]>
    </Native>

    <Native Name="UnitRemoveItem" ReturnType="nothing" ArgumentList="unit whichUnit, item whichItem">
      <![CDATA[native          UnitRemoveItem          takes unit whichUnit, item whichItem returns nothing]]>
    </Native>

    <Native Name="UnitRemoveItemFromSlot" ReturnType="item" ArgumentList="unit whichUnit, integer itemSlot">
      <![CDATA[native          UnitRemoveItemFromSlot  takes unit whichUnit, integer itemSlot returns item]]>
    </Native>

    <Native Name="UnitHasItem" ReturnType="boolean" ArgumentList="unit whichUnit, item whichItem">
      <![CDATA[native          UnitHasItem             takes unit whichUnit, item whichItem returns boolean]]>
    </Native>

    <Native Name="UnitItemInSlot" ReturnType="item" ArgumentList="unit whichUnit, integer itemSlot">
      <![CDATA[native          UnitItemInSlot          takes unit whichUnit, integer itemSlot returns item]]>
    </Native>

    <Native Name="UnitUseItem" ReturnType="boolean" ArgumentList="unit whichUnit, item whichItem">
      <![CDATA[native          UnitUseItem             takes unit whichUnit, item whichItem returns boolean]]>
    </Native>

    <Native Name="UnitUseItemPoint" ReturnType="boolean" ArgumentList="unit whichUnit, item whichItem, real x, real y">
      <![CDATA[native          UnitUseItemPoint        takes unit whichUnit, item whichItem, real x, real y returns boolean]]>
    </Native>

    <Native Name="UnitUseItemTarget" ReturnType="boolean" ArgumentList="unit whichUnit, item whichItem, widget target">
      <![CDATA[native          UnitUseItemTarget       takes unit whichUnit, item whichItem, widget target returns boolean]]>
    </Native>

    <Native Name="GetUnitX" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitX            takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitY" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitY            takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitLoc" ReturnType="location" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitLoc          takes unit whichUnit returns location]]>
    </Native>

    <Native Name="GetUnitFacing" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitFacing       takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitMoveSpeed" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitMoveSpeed    takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitDefaultMoveSpeed" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitDefaultMoveSpeed takes unit whichUnit returns real]]>
    </Native>

    <Native Name="GetUnitState" ReturnType="real" ArgumentList="unit whichUnit, unitstate whichUnitState">
      <![CDATA[constant native GetUnitState        takes unit whichUnit, unitstate whichUnitState returns real]]>
    </Native>

    <Native Name="GetOwningPlayer" ReturnType="player" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetOwningPlayer     takes unit whichUnit returns player]]>
    </Native>

    <Native Name="GetUnitTypeId" ReturnType="integer" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitTypeId       takes unit whichUnit returns integer]]>
    </Native>

    <Native Name="GetUnitRace" ReturnType="race" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitRace         takes unit whichUnit returns race]]>
    </Native>

    <Native Name="GetUnitName" ReturnType="string" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitName         takes unit whichUnit returns string]]>
    </Native>

    <Native Name="GetUnitFoodUsed" ReturnType="integer" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitFoodUsed     takes unit whichUnit returns integer]]>
    </Native>

    <Native Name="GetUnitFoodMade" ReturnType="integer" ArgumentList="unit whichUnit">
      <![CDATA[constant native GetUnitFoodMade     takes unit whichUnit returns integer]]>
    </Native>

    <Native Name="GetFoodMade" ReturnType="integer" ArgumentList="integer unitId">
      <![CDATA[constant native GetFoodMade         takes integer unitId returns integer]]>
    </Native>

    <Native Name="GetFoodUsed" ReturnType="integer" ArgumentList="integer unitId">
      <![CDATA[constant native GetFoodUsed         takes integer unitId returns integer]]>
    </Native>

    <Native Name="SetUnitUseFood" ReturnType="nothing" ArgumentList="unit whichUnit, boolean useFood">
      <![CDATA[native          SetUnitUseFood      takes unit whichUnit, boolean useFood returns nothing]]>
    </Native>

    <Native Name="IsUnitInGroup" ReturnType="boolean" ArgumentList="unit whichUnit, group whichGroup">
      <![CDATA[constant native IsUnitInGroup       takes unit whichUnit, group whichGroup returns boolean]]>
    </Native>

    <Native Name="IsUnitInForce" ReturnType="boolean" ArgumentList="unit whichUnit, force whichForce">
      <![CDATA[constant native IsUnitInForce       takes unit whichUnit, force whichForce returns boolean]]>
    </Native>

    <Native Name="IsUnitOwnedByPlayer" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitOwnedByPlayer takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitAlly" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitAlly          takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitEnemy" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitEnemy         takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitVisible" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitVisible       takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitDetected" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitDetected      takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitInvisible" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitInvisible     takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitFogged" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitFogged        takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitMasked" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitMasked        takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitSelected" ReturnType="boolean" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[constant native IsUnitSelected      takes unit whichUnit, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsUnitRace" ReturnType="boolean" ArgumentList="unit whichUnit, race whichRace">
      <![CDATA[constant native IsUnitRace          takes unit whichUnit, race whichRace returns boolean]]>
    </Native>

    <Native Name="IsUnitType" ReturnType="boolean" ArgumentList="unit whichUnit, unittype whichUnitType">
      <![CDATA[constant native IsUnitType          takes unit whichUnit, unittype whichUnitType returns boolean]]>
    </Native>

    <Native Name="IsUnit" ReturnType="boolean" ArgumentList="unit whichUnit, unit whichSpecifiedUnit">
      <![CDATA[constant native IsUnit              takes unit whichUnit, unit whichSpecifiedUnit returns boolean]]>
    </Native>

    <Native Name="IsUnitInRange" ReturnType="boolean" ArgumentList="unit whichUnit, unit otherUnit, real distance">
      <![CDATA[constant native IsUnitInRange       takes unit whichUnit, unit otherUnit, real distance returns boolean]]>
    </Native>

    <Native Name="IsUnitInRangeXY" ReturnType="boolean" ArgumentList="unit whichUnit, real x, real y, real distance">
      <![CDATA[constant native IsUnitInRangeXY     takes unit whichUnit, real x, real y, real distance returns boolean]]>
    </Native>

    <Native Name="IsUnitInRangeLoc" ReturnType="boolean" ArgumentList="unit whichUnit, location whichLocation, real distance">
      <![CDATA[constant native IsUnitInRangeLoc    takes unit whichUnit, location whichLocation, real distance returns boolean]]>
    </Native>

    <Native Name="IsUnitHidden" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[constant native IsUnitHidden        takes unit whichUnit returns boolean]]>
    </Native>

    <Native Name="IsUnitIllusion" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[constant native IsUnitIllusion      takes unit whichUnit returns boolean]]>
    </Native>

    <Native Name="IsUnitInTransport" ReturnType="boolean" ArgumentList="unit whichUnit, unit whichTransport">
      <![CDATA[constant native IsUnitInTransport   takes unit whichUnit, unit whichTransport returns boolean]]>
    </Native>

    <Native Name="IsUnitLoaded" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[constant native IsUnitLoaded        takes unit whichUnit returns boolean]]>
    </Native>

    <Native Name="IsHeroUnitId" ReturnType="boolean" ArgumentList="integer unitId">
      <![CDATA[constant native IsHeroUnitId        takes integer unitId returns boolean]]>
    </Native>

    <Native Name="IsUnitIdType" ReturnType="boolean" ArgumentList="integer unitId, unittype whichUnitType">
      <![CDATA[constant native IsUnitIdType        takes integer unitId, unittype whichUnitType returns boolean]]>
    </Native>

    <Native Name="UnitShareVision" ReturnType="nothing" ArgumentList="unit whichUnit, player whichPlayer, boolean share">
      <![CDATA[native UnitShareVision              takes unit whichUnit, player whichPlayer, boolean share returns nothing]]>
    </Native>

    <Native Name="UnitSuspendDecay" ReturnType="nothing" ArgumentList="unit whichUnit, boolean suspend">
      <![CDATA[native UnitSuspendDecay             takes unit whichUnit, boolean suspend returns nothing]]>
    </Native>

    <Native Name="UnitAddAbility" ReturnType="boolean" ArgumentList="unit whichUnit, integer abilityId">
      <![CDATA[native UnitAddAbility               takes unit whichUnit, integer abilityId returns boolean]]>
    </Native>

    <Native Name="UnitRemoveAbility" ReturnType="boolean" ArgumentList="unit whichUnit, integer abilityId">
      <![CDATA[native UnitRemoveAbility            takes unit whichUnit, integer abilityId returns boolean]]>
    </Native>

    <Native Name="UnitRemoveBuffs" ReturnType="nothing" ArgumentList="unit whichUnit, boolean removePositive, boolean removeNegative">
      <![CDATA[native UnitRemoveBuffs              takes unit whichUnit, boolean removePositive, boolean removeNegative returns nothing]]>
    </Native>

    <Native Name="UnitRemoveBuffsEx" ReturnType="nothing" ArgumentList="unit whichUnit, boolean removePositive, boolean removeNegative, boolean magic, boolean physical, boolean timedLife, boolean aura, boolean autoDispel">
      <![CDATA[native UnitRemoveBuffsEx            takes unit whichUnit, boolean removePositive, boolean removeNegative, boolean magic, boolean physical, boolean timedLife, boolean aura, boolean autoDispel returns nothing]]>
    </Native>

    <Native Name="UnitHasBuffsEx" ReturnType="boolean" ArgumentList="unit whichUnit, boolean removePositive, boolean removeNegative, boolean magic, boolean physical, boolean timedLife, boolean aura, boolean autoDispel">
      <![CDATA[native UnitHasBuffsEx               takes unit whichUnit, boolean removePositive, boolean removeNegative, boolean magic, boolean physical, boolean timedLife, boolean aura, boolean autoDispel returns boolean]]>
    </Native>

    <Native Name="UnitCountBuffsEx" ReturnType="integer" ArgumentList="unit whichUnit, boolean removePositive, boolean removeNegative, boolean magic, boolean physical, boolean timedLife, boolean aura, boolean autoDispel">
      <![CDATA[native UnitCountBuffsEx             takes unit whichUnit, boolean removePositive, boolean removeNegative, boolean magic, boolean physical, boolean timedLife, boolean aura, boolean autoDispel returns integer]]>
    </Native>

    <Native Name="UnitAddSleep" ReturnType="nothing" ArgumentList="unit whichUnit, boolean add">
      <![CDATA[native UnitAddSleep                 takes unit whichUnit, boolean add returns nothing]]>
    </Native>

    <Native Name="UnitCanSleep" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[native UnitCanSleep                 takes unit whichUnit returns boolean]]>
    </Native>

    <Native Name="UnitAddSleepPerm" ReturnType="nothing" ArgumentList="unit whichUnit, boolean add">
      <![CDATA[native UnitAddSleepPerm             takes unit whichUnit, boolean add returns nothing]]>
    </Native>

    <Native Name="UnitCanSleepPerm" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[native UnitCanSleepPerm             takes unit whichUnit returns boolean]]>
    </Native>

    <Native Name="UnitIsSleeping" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[native UnitIsSleeping               takes unit whichUnit returns boolean]]>
    </Native>

    <Native Name="UnitWakeUp" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[native UnitWakeUp                   takes unit whichUnit returns nothing]]>
    </Native>

    <Native Name="UnitApplyTimedLife" ReturnType="nothing" ArgumentList="unit whichUnit, integer buffId, real duration">
      <![CDATA[native UnitApplyTimedLife           takes unit whichUnit, integer buffId, real duration returns nothing]]>
    </Native>

    <Native Name="UnitIgnoreAlarm" ReturnType="boolean" ArgumentList="unit whichUnit, boolean flag">
      <![CDATA[native UnitIgnoreAlarm              takes unit whichUnit, boolean flag returns boolean]]>
    </Native>

    <Native Name="UnitIgnoreAlarmToggled" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[native UnitIgnoreAlarmToggled       takes unit whichUnit returns boolean]]>
    </Native>

    <Native Name="UnitResetCooldown" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[native UnitResetCooldown            takes unit whichUnit returns nothing]]>
    </Native>

    <Native Name="UnitSetConstructionProgress" ReturnType="nothing" ArgumentList="unit whichUnit, integer constructionPercentage">
      <![CDATA[native UnitSetConstructionProgress  takes unit whichUnit, integer constructionPercentage returns nothing]]>
    </Native>

    <Native Name="UnitSetUpgradeProgress" ReturnType="nothing" ArgumentList="unit whichUnit, integer upgradePercentage">
      <![CDATA[native UnitSetUpgradeProgress       takes unit whichUnit, integer upgradePercentage returns nothing]]>
    </Native>

    <Native Name="UnitPauseTimedLife" ReturnType="nothing" ArgumentList="unit whichUnit, boolean flag">
      <![CDATA[native UnitPauseTimedLife           takes unit whichUnit, boolean flag returns nothing]]>
    </Native>

    <Native Name="UnitSetUsesAltIcon" ReturnType="nothing" ArgumentList="unit whichUnit, boolean flag">
      <![CDATA[native UnitSetUsesAltIcon           takes unit whichUnit, boolean flag returns nothing]]>
    </Native>

    <Native Name="IssueImmediateOrder" ReturnType="boolean" ArgumentList="unit whichUnit, string order">
      <![CDATA[native IssueImmediateOrder          takes unit whichUnit, string order returns boolean]]>
    </Native>

    <Native Name="IssueImmediateOrderById" ReturnType="boolean" ArgumentList="unit whichUnit, integer order">
      <![CDATA[native IssueImmediateOrderById      takes unit whichUnit, integer order returns boolean]]>
    </Native>

    <Native Name="IssuePointOrder" ReturnType="boolean" ArgumentList="unit whichUnit, string order, real x, real y">
      <![CDATA[native IssuePointOrder              takes unit whichUnit, string order, real x, real y returns boolean]]>
    </Native>

    <Native Name="IssuePointOrderLoc" ReturnType="boolean" ArgumentList="unit whichUnit, string order, location whichLocation">
      <![CDATA[native IssuePointOrderLoc           takes unit whichUnit, string order, location whichLocation returns boolean]]>
    </Native>

    <Native Name="IssuePointOrderById" ReturnType="boolean" ArgumentList="unit whichUnit, integer order, real x, real y">
      <![CDATA[native IssuePointOrderById          takes unit whichUnit, integer order, real x, real y returns boolean]]>
    </Native>

    <Native Name="IssuePointOrderByIdLoc" ReturnType="boolean" ArgumentList="unit whichUnit, integer order, location whichLocation">
      <![CDATA[native IssuePointOrderByIdLoc       takes unit whichUnit, integer order, location whichLocation returns boolean]]>
    </Native>

    <Native Name="IssueTargetOrder" ReturnType="boolean" ArgumentList="unit whichUnit, string order, widget targetWidget">
      <![CDATA[native IssueTargetOrder             takes unit whichUnit, string order, widget targetWidget returns boolean]]>
    </Native>

    <Native Name="IssueTargetOrderById" ReturnType="boolean" ArgumentList="unit whichUnit, integer order, widget targetWidget">
      <![CDATA[native IssueTargetOrderById         takes unit whichUnit, integer order, widget targetWidget returns boolean]]>
    </Native>

    <Native Name="IssueInstantTargetOrder" ReturnType="boolean" ArgumentList="unit whichUnit, string order, widget targetWidget, widget instantTargetWidget">
      <![CDATA[native IssueInstantTargetOrder      takes unit whichUnit, string order, widget targetWidget, widget instantTargetWidget returns boolean]]>
    </Native>

    <Native Name="IssueInstantTargetOrderById" ReturnType="boolean" ArgumentList="unit whichUnit, integer order, widget targetWidget, widget instantTargetWidget">
      <![CDATA[native IssueInstantTargetOrderById  takes unit whichUnit, integer order, widget targetWidget, widget instantTargetWidget returns boolean]]>
    </Native>

    <Native Name="IssueBuildOrder" ReturnType="boolean" ArgumentList="unit whichPeon, string unitToBuild, real x, real y">
      <![CDATA[native IssueBuildOrder              takes unit whichPeon, string unitToBuild, real x, real y returns boolean]]>
    </Native>

    <Native Name="IssueBuildOrderById" ReturnType="boolean" ArgumentList="unit whichPeon, integer unitId, real x, real y">
      <![CDATA[native IssueBuildOrderById          takes unit whichPeon, integer unitId, real x, real y returns boolean]]>
    </Native>

    <Native Name="IssueNeutralImmediateOrder" ReturnType="boolean" ArgumentList="player forWhichPlayer, unit neutralStructure, string unitToBuild">
      <![CDATA[native IssueNeutralImmediateOrder       takes player forWhichPlayer, unit neutralStructure, string unitToBuild returns boolean]]>
    </Native>

    <Native Name="IssueNeutralImmediateOrderById" ReturnType="boolean" ArgumentList="player forWhichPlayer,unit neutralStructure, integer unitId">
      <![CDATA[native IssueNeutralImmediateOrderById   takes player forWhichPlayer,unit neutralStructure, integer unitId returns boolean]]>
    </Native>

    <Native Name="IssueNeutralPointOrder" ReturnType="boolean" ArgumentList="player forWhichPlayer,unit neutralStructure, string unitToBuild, real x, real y">
      <![CDATA[native IssueNeutralPointOrder           takes player forWhichPlayer,unit neutralStructure, string unitToBuild, real x, real y returns boolean]]>
    </Native>

    <Native Name="IssueNeutralPointOrderById" ReturnType="boolean" ArgumentList="player forWhichPlayer,unit neutralStructure, integer unitId, real x, real y">
      <![CDATA[native IssueNeutralPointOrderById       takes player forWhichPlayer,unit neutralStructure, integer unitId, real x, real y returns boolean]]>
    </Native>

    <Native Name="IssueNeutralTargetOrder" ReturnType="boolean" ArgumentList="player forWhichPlayer,unit neutralStructure, string unitToBuild, widget target">
      <![CDATA[native IssueNeutralTargetOrder          takes player forWhichPlayer,unit neutralStructure, string unitToBuild, widget target returns boolean]]>
    </Native>

    <Native Name="IssueNeutralTargetOrderById" ReturnType="boolean" ArgumentList="player forWhichPlayer,unit neutralStructure, integer unitId, widget target">
      <![CDATA[native IssueNeutralTargetOrderById      takes player forWhichPlayer,unit neutralStructure, integer unitId, widget target returns boolean]]>
    </Native>

    <Native Name="SetResourceAmount" ReturnType="nothing" ArgumentList="unit whichUnit, integer amount">
      <![CDATA[native SetResourceAmount            takes unit whichUnit, integer amount returns nothing]]>
    </Native>

    <Native Name="AddResourceAmount" ReturnType="nothing" ArgumentList="unit whichUnit, integer amount">
      <![CDATA[native AddResourceAmount            takes unit whichUnit, integer amount returns nothing]]>
    </Native>

    <Native Name="GetResourceAmount" ReturnType="integer" ArgumentList="unit whichUnit">
      <![CDATA[native GetResourceAmount            takes unit whichUnit returns integer]]>
    </Native>

    <Native Name="WaygateGetDestinationX" ReturnType="real" ArgumentList="unit waygate">
      <![CDATA[native WaygateGetDestinationX       takes unit waygate returns real]]>
    </Native>

    <Native Name="WaygateGetDestinationY" ReturnType="real" ArgumentList="unit waygate">
      <![CDATA[native WaygateGetDestinationY       takes unit waygate returns real]]>
    </Native>

    <Native Name="WaygateSetDestination" ReturnType="nothing" ArgumentList="unit waygate, real x, real y">
      <![CDATA[native WaygateSetDestination        takes unit waygate, real x, real y returns nothing]]>
    </Native>

    <Native Name="WaygateActivate" ReturnType="nothing" ArgumentList="unit waygate, boolean activate">
      <![CDATA[native WaygateActivate              takes unit waygate, boolean activate returns nothing]]>
    </Native>

    <Native Name="WaygateIsActive" ReturnType="boolean" ArgumentList="unit waygate">
      <![CDATA[native WaygateIsActive              takes unit waygate returns boolean]]>
    </Native>

    <Native Name="AddItemToAllStock" ReturnType="nothing" ArgumentList="integer itemId, integer currentStock, integer stockMax">
      <![CDATA[native AddItemToAllStock            takes integer itemId, integer currentStock, integer stockMax returns nothing]]>
    </Native>

    <Native Name="AddItemToStock" ReturnType="nothing" ArgumentList="unit whichUnit, integer itemId, integer currentStock, integer stockMax">
      <![CDATA[native AddItemToStock               takes unit whichUnit, integer itemId, integer currentStock, integer stockMax returns nothing]]>
    </Native>

    <Native Name="AddUnitToAllStock" ReturnType="nothing" ArgumentList="integer unitId, integer currentStock, integer stockMax">
      <![CDATA[native AddUnitToAllStock            takes integer unitId, integer currentStock, integer stockMax returns nothing]]>
    </Native>

    <Native Name="AddUnitToStock" ReturnType="nothing" ArgumentList="unit whichUnit, integer unitId, integer currentStock, integer stockMax">
      <![CDATA[native AddUnitToStock               takes unit whichUnit, integer unitId, integer currentStock, integer stockMax returns nothing]]>
    </Native>

    <Native Name="RemoveItemFromAllStock" ReturnType="nothing" ArgumentList="integer itemId">
      <![CDATA[native RemoveItemFromAllStock       takes integer itemId returns nothing]]>
    </Native>

    <Native Name="RemoveItemFromStock" ReturnType="nothing" ArgumentList="unit whichUnit, integer itemId">
      <![CDATA[native RemoveItemFromStock          takes unit whichUnit, integer itemId returns nothing]]>
    </Native>

    <Native Name="RemoveUnitFromAllStock" ReturnType="nothing" ArgumentList="integer unitId">
      <![CDATA[native RemoveUnitFromAllStock       takes integer unitId returns nothing]]>
    </Native>

    <Native Name="RemoveUnitFromStock" ReturnType="nothing" ArgumentList="unit whichUnit, integer unitId">
      <![CDATA[native RemoveUnitFromStock          takes unit whichUnit, integer unitId returns nothing]]>
    </Native>

    <Native Name="SetAllItemTypeSlots" ReturnType="nothing" ArgumentList="integer slots">
      <![CDATA[native SetAllItemTypeSlots          takes integer slots returns nothing]]>
    </Native>

    <Native Name="SetAllUnitTypeSlots" ReturnType="nothing" ArgumentList="integer slots">
      <![CDATA[native SetAllUnitTypeSlots          takes integer slots returns nothing]]>
    </Native>

    <Native Name="SetItemTypeSlots" ReturnType="nothing" ArgumentList="unit whichUnit, integer slots">
      <![CDATA[native SetItemTypeSlots             takes unit whichUnit, integer slots returns nothing]]>
    </Native>

    <Native Name="SetUnitTypeSlots" ReturnType="nothing" ArgumentList="unit whichUnit, integer slots">
      <![CDATA[native SetUnitTypeSlots             takes unit whichUnit, integer slots returns nothing]]>
    </Native>

    <Native Name="GetUnitUserData" ReturnType="integer" ArgumentList="unit whichUnit">
      <![CDATA[native GetUnitUserData              takes unit whichUnit returns integer]]>
    </Native>

    <Native Name="SetUnitUserData" ReturnType="nothing" ArgumentList="unit whichUnit, integer data">
      <![CDATA[native SetUnitUserData              takes unit whichUnit, integer data returns nothing]]>
    </Native>

    <Native Name="Player" ReturnType="player" ArgumentList="integer number">
      <![CDATA[constant native Player              takes integer number returns player]]>
    </Native>

    <Native Name="GetLocalPlayer" ReturnType="player" ArgumentList="nothing">
      <![CDATA[constant native GetLocalPlayer      takes nothing returns player]]>
    </Native>

    <Native Name="IsPlayerAlly" ReturnType="boolean" ArgumentList="player whichPlayer, player otherPlayer">
      <![CDATA[constant native IsPlayerAlly        takes player whichPlayer, player otherPlayer returns boolean]]>
    </Native>

    <Native Name="IsPlayerEnemy" ReturnType="boolean" ArgumentList="player whichPlayer, player otherPlayer">
      <![CDATA[constant native IsPlayerEnemy       takes player whichPlayer, player otherPlayer returns boolean]]>
    </Native>

    <Native Name="IsPlayerInForce" ReturnType="boolean" ArgumentList="player whichPlayer, force whichForce">
      <![CDATA[constant native IsPlayerInForce     takes player whichPlayer, force whichForce returns boolean]]>
    </Native>

    <Native Name="IsPlayerObserver" ReturnType="boolean" ArgumentList="player whichPlayer">
      <![CDATA[constant native IsPlayerObserver    takes player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsVisibleToPlayer" ReturnType="boolean" ArgumentList="real x, real y, player whichPlayer">
      <![CDATA[constant native IsVisibleToPlayer           takes real x, real y, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsLocationVisibleToPlayer" ReturnType="boolean" ArgumentList="location whichLocation, player whichPlayer">
      <![CDATA[constant native IsLocationVisibleToPlayer   takes location whichLocation, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsFoggedToPlayer" ReturnType="boolean" ArgumentList="real x, real y, player whichPlayer">
      <![CDATA[constant native IsFoggedToPlayer            takes real x, real y, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsLocationFoggedToPlayer" ReturnType="boolean" ArgumentList="location whichLocation, player whichPlayer">
      <![CDATA[constant native IsLocationFoggedToPlayer    takes location whichLocation, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsMaskedToPlayer" ReturnType="boolean" ArgumentList="real x, real y, player whichPlayer">
      <![CDATA[constant native IsMaskedToPlayer            takes real x, real y, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="IsLocationMaskedToPlayer" ReturnType="boolean" ArgumentList="location whichLocation, player whichPlayer">
      <![CDATA[constant native IsLocationMaskedToPlayer    takes location whichLocation, player whichPlayer returns boolean]]>
    </Native>

    <Native Name="GetPlayerRace" ReturnType="race" ArgumentList="player whichPlayer">
      <![CDATA[constant native GetPlayerRace           takes player whichPlayer returns race]]>
    </Native>

    <Native Name="GetPlayerId" ReturnType="integer" ArgumentList="player whichPlayer">
      <![CDATA[constant native GetPlayerId             takes player whichPlayer returns integer]]>
    </Native>

    <Native Name="GetPlayerUnitCount" ReturnType="integer" ArgumentList="player whichPlayer, boolean includeIncomplete">
      <![CDATA[constant native GetPlayerUnitCount      takes player whichPlayer, boolean includeIncomplete returns integer]]>
    </Native>

    <Native Name="GetPlayerTypedUnitCount" ReturnType="integer" ArgumentList="player whichPlayer, string unitName, boolean includeIncomplete, boolean includeUpgrades">
      <![CDATA[constant native GetPlayerTypedUnitCount takes player whichPlayer, string unitName, boolean includeIncomplete, boolean includeUpgrades returns integer]]>
    </Native>

    <Native Name="GetPlayerStructureCount" ReturnType="integer" ArgumentList="player whichPlayer, boolean includeIncomplete">
      <![CDATA[constant native GetPlayerStructureCount takes player whichPlayer, boolean includeIncomplete returns integer]]>
    </Native>

    <Native Name="GetPlayerState" ReturnType="integer" ArgumentList="player whichPlayer, playerstate whichPlayerState">
      <![CDATA[constant native GetPlayerState          takes player whichPlayer, playerstate whichPlayerState returns integer]]>
    </Native>

    <Native Name="GetPlayerAlliance" ReturnType="boolean" ArgumentList="player sourcePlayer, player otherPlayer, alliancetype whichAllianceSetting">
      <![CDATA[constant native GetPlayerAlliance       takes player sourcePlayer, player otherPlayer, alliancetype whichAllianceSetting returns boolean]]>
    </Native>

    <Native Name="GetPlayerHandicap" ReturnType="real" ArgumentList="player whichPlayer">
      <![CDATA[constant native GetPlayerHandicap       takes player whichPlayer returns real]]>
    </Native>

    <Native Name="GetPlayerHandicapXP" ReturnType="real" ArgumentList="player whichPlayer">
      <![CDATA[constant native GetPlayerHandicapXP     takes player whichPlayer returns real]]>
    </Native>

    <Native Name="SetPlayerHandicap" ReturnType="nothing" ArgumentList="player whichPlayer, real handicap">
      <![CDATA[constant native SetPlayerHandicap       takes player whichPlayer, real handicap returns nothing]]>
    </Native>

    <Native Name="SetPlayerHandicapXP" ReturnType="nothing" ArgumentList="player whichPlayer, real handicap">
      <![CDATA[constant native SetPlayerHandicapXP     takes player whichPlayer, real handicap returns nothing]]>
    </Native>

    <Native Name="SetPlayerTechMaxAllowed" ReturnType="nothing" ArgumentList="player whichPlayer, integer techid, integer maximum">
      <![CDATA[constant native SetPlayerTechMaxAllowed takes player whichPlayer, integer techid, integer maximum returns nothing]]>
    </Native>

    <Native Name="GetPlayerTechMaxAllowed" ReturnType="integer" ArgumentList="player whichPlayer, integer techid">
      <![CDATA[constant native GetPlayerTechMaxAllowed takes player whichPlayer, integer techid returns integer]]>
    </Native>

    <Native Name="AddPlayerTechResearched" ReturnType="nothing" ArgumentList="player whichPlayer, integer techid, integer levels">
      <![CDATA[constant native AddPlayerTechResearched takes player whichPlayer, integer techid, integer levels returns nothing]]>
    </Native>

    <Native Name="SetPlayerTechResearched" ReturnType="nothing" ArgumentList="player whichPlayer, integer techid, integer setToLevel">
      <![CDATA[constant native SetPlayerTechResearched takes player whichPlayer, integer techid, integer setToLevel returns nothing]]>
    </Native>

    <Native Name="GetPlayerTechResearched" ReturnType="boolean" ArgumentList="player whichPlayer, integer techid, boolean specificonly">
      <![CDATA[constant native GetPlayerTechResearched takes player whichPlayer, integer techid, boolean specificonly returns boolean]]>
    </Native>

    <Native Name="GetPlayerTechCount" ReturnType="integer" ArgumentList="player whichPlayer, integer techid, boolean specificonly">
      <![CDATA[constant native GetPlayerTechCount      takes player whichPlayer, integer techid, boolean specificonly returns integer]]>
    </Native>

    <Native Name="SetPlayerUnitsOwner" ReturnType="nothing" ArgumentList="player whichPlayer, integer newOwner">
      <![CDATA[native SetPlayerUnitsOwner takes player whichPlayer, integer newOwner returns nothing]]>
    </Native>

    <Native Name="CripplePlayer" ReturnType="nothing" ArgumentList="player whichPlayer, force toWhichPlayers, boolean flag">
      <![CDATA[native CripplePlayer takes player whichPlayer, force toWhichPlayers, boolean flag returns nothing]]>
    </Native>

    <Native Name="SetPlayerAbilityAvailable" ReturnType="nothing" ArgumentList="player whichPlayer, integer abilid, boolean avail">
      <![CDATA[native SetPlayerAbilityAvailable        takes player whichPlayer, integer abilid, boolean avail returns nothing]]>
    </Native>

    <Native Name="SetPlayerState" ReturnType="nothing" ArgumentList="player whichPlayer, playerstate whichPlayerState, integer value">
      <![CDATA[native SetPlayerState   takes player whichPlayer, playerstate whichPlayerState, integer value returns nothing]]>
    </Native>

    <Native Name="RemovePlayer" ReturnType="nothing" ArgumentList="player whichPlayer, playergameresult gameResult">
      <![CDATA[native RemovePlayer     takes player whichPlayer, playergameresult gameResult returns nothing]]>
    </Native>

    <Native Name="CachePlayerHeroData" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[native CachePlayerHeroData takes player whichPlayer returns nothing]]>
    </Native>

    <Native Name="SetFogStateRect" ReturnType="nothing" ArgumentList="player forWhichPlayer, fogstate whichState, rect where, boolean useSharedVision">
      <![CDATA[native  SetFogStateRect      takes player forWhichPlayer, fogstate whichState, rect where, boolean useSharedVision returns nothing]]>
    </Native>

    <Native Name="SetFogStateRadius" ReturnType="nothing" ArgumentList="player forWhichPlayer, fogstate whichState, real centerx, real centerY, real radius, boolean useSharedVision">
      <![CDATA[native  SetFogStateRadius    takes player forWhichPlayer, fogstate whichState, real centerx, real centerY, real radius, boolean useSharedVision returns nothing]]>
    </Native>

    <Native Name="SetFogStateRadiusLoc" ReturnType="nothing" ArgumentList="player forWhichPlayer, fogstate whichState, location center, real radius, boolean useSharedVision">
      <![CDATA[native  SetFogStateRadiusLoc takes player forWhichPlayer, fogstate whichState, location center, real radius, boolean useSharedVision returns nothing]]>
    </Native>

    <Native Name="FogMaskEnable" ReturnType="nothing" ArgumentList="boolean enable">
      <![CDATA[native  FogMaskEnable        takes boolean enable returns nothing]]>
    </Native>

    <Native Name="IsFogMaskEnabled" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[native  IsFogMaskEnabled     takes nothing returns boolean]]>
    </Native>

    <Native Name="FogEnable" ReturnType="nothing" ArgumentList="boolean enable">
      <![CDATA[native  FogEnable            takes boolean enable returns nothing]]>
    </Native>

    <Native Name="IsFogEnabled" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[native  IsFogEnabled         takes nothing returns boolean]]>
    </Native>

    <Native Name="CreateFogModifierRect" ReturnType="fogmodifier" ArgumentList="player forWhichPlayer, fogstate whichState, rect where, boolean useSharedVision, boolean afterUnits">
      <![CDATA[native CreateFogModifierRect        takes player forWhichPlayer, fogstate whichState, rect where, boolean useSharedVision, boolean afterUnits returns fogmodifier]]>
    </Native>

    <Native Name="CreateFogModifierRadius" ReturnType="fogmodifier" ArgumentList="player forWhichPlayer, fogstate whichState, real centerx, real centerY, real radius, boolean useSharedVision, boolean afterUnits">
      <![CDATA[native CreateFogModifierRadius      takes player forWhichPlayer, fogstate whichState, real centerx, real centerY, real radius, boolean useSharedVision, boolean afterUnits returns fogmodifier]]>
    </Native>

    <Native Name="CreateFogModifierRadiusLoc" ReturnType="fogmodifier" ArgumentList="player forWhichPlayer, fogstate whichState, location center, real radius, boolean useSharedVision, boolean afterUnits">
      <![CDATA[native CreateFogModifierRadiusLoc   takes player forWhichPlayer, fogstate whichState, location center, real radius, boolean useSharedVision, boolean afterUnits returns fogmodifier]]>
    </Native>

    <Native Name="DestroyFogModifier" ReturnType="nothing" ArgumentList="fogmodifier whichFogModifier">
      <![CDATA[native DestroyFogModifier           takes fogmodifier whichFogModifier returns nothing]]>
    </Native>

    <Native Name="FogModifierStart" ReturnType="nothing" ArgumentList="fogmodifier whichFogModifier">
      <![CDATA[native FogModifierStart             takes fogmodifier whichFogModifier returns nothing]]>
    </Native>

    <Native Name="FogModifierStop" ReturnType="nothing" ArgumentList="fogmodifier whichFogModifier">
      <![CDATA[native FogModifierStop              takes fogmodifier whichFogModifier returns nothing]]>
    </Native>

    <Native Name="VersionGet" ReturnType="version" ArgumentList="nothing">
      <![CDATA[native VersionGet takes nothing returns version]]>
    </Native>

    <Native Name="VersionCompatible" ReturnType="boolean" ArgumentList="version whichVersion">
      <![CDATA[native VersionCompatible takes version whichVersion returns boolean]]>
    </Native>

    <Native Name="VersionSupported" ReturnType="boolean" ArgumentList="version whichVersion">
      <![CDATA[native VersionSupported takes version whichVersion returns boolean]]>
    </Native>

    <Native Name="EndGame" ReturnType="nothing" ArgumentList="boolean doScoreScreen">
      <![CDATA[native EndGame takes boolean doScoreScreen returns nothing]]>
    </Native>

    <Native Name="ChangeLevel" ReturnType="nothing" ArgumentList="string newLevel, boolean doScoreScreen">
      <![CDATA[native          ChangeLevel         takes string newLevel, boolean doScoreScreen returns nothing]]>
    </Native>

    <Native Name="RestartGame" ReturnType="nothing" ArgumentList="boolean doScoreScreen">
      <![CDATA[native          RestartGame         takes boolean doScoreScreen returns nothing]]>
    </Native>

    <Native Name="ReloadGame" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native          ReloadGame          takes nothing returns nothing]]>
    </Native>

    <Native Name="SetCampaignMenuRace" ReturnType="nothing" ArgumentList="race r">
      <![CDATA[native          SetCampaignMenuRace takes race r returns nothing]]>
    </Native>

    <Native Name="SetCampaignMenuRaceEx" ReturnType="nothing" ArgumentList="integer campaignIndex">
      <![CDATA[native          SetCampaignMenuRaceEx takes integer campaignIndex returns nothing]]>
    </Native>

    <Native Name="ForceCampaignSelectScreen" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native          ForceCampaignSelectScreen takes nothing returns nothing]]>
    </Native>

    <Native Name="LoadGame" ReturnType="nothing" ArgumentList="string saveFileName, boolean doScoreScreen">
      <![CDATA[native          LoadGame            takes string saveFileName, boolean doScoreScreen returns nothing]]>
    </Native>

    <Native Name="SaveGame" ReturnType="nothing" ArgumentList="string saveFileName">
      <![CDATA[native          SaveGame            takes string saveFileName returns nothing]]>
    </Native>

    <Native Name="RenameSaveDirectory" ReturnType="boolean" ArgumentList="string sourceDirName, string destDirName">
      <![CDATA[native          RenameSaveDirectory takes string sourceDirName, string destDirName returns boolean]]>
    </Native>

    <Native Name="RemoveSaveDirectory" ReturnType="boolean" ArgumentList="string sourceDirName">
      <![CDATA[native          RemoveSaveDirectory takes string sourceDirName returns boolean]]>
    </Native>

    <Native Name="CopySaveGame" ReturnType="boolean" ArgumentList="string sourceSaveName, string destSaveName">
      <![CDATA[native          CopySaveGame        takes string sourceSaveName, string destSaveName returns boolean]]>
    </Native>

    <Native Name="SaveGameExists" ReturnType="boolean" ArgumentList="string saveName">
      <![CDATA[native          SaveGameExists      takes string saveName returns boolean]]>
    </Native>

    <Native Name="SyncSelections" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native          SyncSelections      takes nothing returns nothing]]>
    </Native>

    <Native Name="SetFloatGameState" ReturnType="nothing" ArgumentList="fgamestate whichFloatGameState, real value">
      <![CDATA[native          SetFloatGameState   takes fgamestate whichFloatGameState, real value returns nothing]]>
    </Native>

    <Native Name="GetFloatGameState" ReturnType="real" ArgumentList="fgamestate whichFloatGameState">
      <![CDATA[constant native GetFloatGameState   takes fgamestate whichFloatGameState returns real]]>
    </Native>

    <Native Name="SetIntegerGameState" ReturnType="nothing" ArgumentList="igamestate whichIntegerGameState, integer value">
      <![CDATA[native          SetIntegerGameState takes igamestate whichIntegerGameState, integer value returns nothing]]>
    </Native>

    <Native Name="GetIntegerGameState" ReturnType="integer" ArgumentList="igamestate whichIntegerGameState">
      <![CDATA[constant native GetIntegerGameState takes igamestate whichIntegerGameState returns integer]]>
    </Native>

    <Native Name="SetTutorialCleared" ReturnType="nothing" ArgumentList="boolean cleared">
      <![CDATA[native  SetTutorialCleared      takes boolean cleared returns nothing]]>
    </Native>

    <Native Name="SetMissionAvailable" ReturnType="nothing" ArgumentList="integer campaignNumber, integer missionNumber, boolean available">
      <![CDATA[native  SetMissionAvailable     takes integer campaignNumber, integer missionNumber, boolean available returns nothing]]>
    </Native>

    <Native Name="SetCampaignAvailable" ReturnType="nothing" ArgumentList="integer campaignNumber, boolean available">
      <![CDATA[native  SetCampaignAvailable    takes integer campaignNumber, boolean available  returns nothing]]>
    </Native>

    <Native Name="SetOpCinematicAvailable" ReturnType="nothing" ArgumentList="integer campaignNumber, boolean available">
      <![CDATA[native  SetOpCinematicAvailable takes integer campaignNumber, boolean available  returns nothing]]>
    </Native>

    <Native Name="SetEdCinematicAvailable" ReturnType="nothing" ArgumentList="integer campaignNumber, boolean available">
      <![CDATA[native  SetEdCinematicAvailable takes integer campaignNumber, boolean available  returns nothing]]>
    </Native>

    <Native Name="GetDefaultDifficulty" ReturnType="gamedifficulty" ArgumentList="nothing">
      <![CDATA[native  GetDefaultDifficulty    takes nothing returns gamedifficulty]]>
    </Native>

    <Native Name="SetDefaultDifficulty" ReturnType="nothing" ArgumentList="gamedifficulty g">
      <![CDATA[native  SetDefaultDifficulty    takes gamedifficulty g returns nothing]]>
    </Native>

    <Native Name="SetCustomCampaignButtonVisible" ReturnType="nothing" ArgumentList="integer whichButton, boolean visible">
      <![CDATA[native  SetCustomCampaignButtonVisible  takes integer whichButton, boolean visible returns nothing]]>
    </Native>

    <Native Name="GetCustomCampaignButtonVisible" ReturnType="boolean" ArgumentList="integer whichButton">
      <![CDATA[native  GetCustomCampaignButtonVisible  takes integer whichButton returns boolean]]>
    </Native>

    <Native Name="DoNotSaveReplay" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native  DoNotSaveReplay         takes nothing returns nothing]]>
    </Native>

    <Native Name="DialogCreate" ReturnType="dialog" ArgumentList="nothing">
      <![CDATA[native DialogCreate                 takes nothing returns dialog]]>
    </Native>

    <Native Name="DialogDestroy" ReturnType="nothing" ArgumentList="dialog whichDialog">
      <![CDATA[native DialogDestroy                takes dialog whichDialog returns nothing]]>
    </Native>

    <Native Name="DialogClear" ReturnType="nothing" ArgumentList="dialog whichDialog">
      <![CDATA[native DialogClear                  takes dialog whichDialog returns nothing]]>
    </Native>

    <Native Name="DialogSetMessage" ReturnType="nothing" ArgumentList="dialog whichDialog, string messageText">
      <![CDATA[native DialogSetMessage             takes dialog whichDialog, string messageText returns nothing]]>
    </Native>

    <Native Name="DialogAddButton" ReturnType="button" ArgumentList="dialog whichDialog, string buttonText, integer hotkey">
      <![CDATA[native DialogAddButton              takes dialog whichDialog, string buttonText, integer hotkey returns button]]>
    </Native>

    <Native Name="DialogAddQuitButton" ReturnType="button" ArgumentList="dialog whichDialog, boolean doScoreScreen, string buttonText, integer hotkey">
      <![CDATA[native DialogAddQuitButton          takes dialog whichDialog, boolean doScoreScreen, string buttonText, integer hotkey returns button]]>
    </Native>

    <Native Name="DialogDisplay" ReturnType="nothing" ArgumentList="player whichPlayer, dialog whichDialog, boolean flag">
      <![CDATA[native DialogDisplay                takes player whichPlayer, dialog whichDialog, boolean flag returns nothing]]>
    </Native>

    <Native Name="ReloadGameCachesFromDisk" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[native  ReloadGameCachesFromDisk takes nothing returns boolean]]>
    </Native>

    <Native Name="InitGameCache" ReturnType="gamecache" ArgumentList="string campaignFile">
      <![CDATA[native  InitGameCache   takes string campaignFile returns gamecache]]>
    </Native>

    <Native Name="SaveGameCache" ReturnType="boolean" ArgumentList="gamecache whichCache">
      <![CDATA[native  SaveGameCache   takes gamecache whichCache returns boolean]]>
    </Native>

    <Native Name="StoreInteger" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key, integer value">
      <![CDATA[native  StoreInteger    takes gamecache cache, string missionKey, string key, integer value returns nothing]]>
    </Native>

    <Native Name="StoreReal" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key, real value">
      <![CDATA[native  StoreReal       takes gamecache cache, string missionKey, string key, real value returns nothing]]>
    </Native>

    <Native Name="StoreBoolean" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key, boolean value">
      <![CDATA[native  StoreBoolean    takes gamecache cache, string missionKey, string key, boolean value returns nothing]]>
    </Native>

    <Native Name="StoreUnit" ReturnType="boolean" ArgumentList="gamecache cache, string missionKey, string key, unit whichUnit">
      <![CDATA[native  StoreUnit       takes gamecache cache, string missionKey, string key, unit whichUnit returns boolean]]>
    </Native>

    <Native Name="StoreString" ReturnType="boolean" ArgumentList="gamecache cache, string missionKey, string key, string value">
      <![CDATA[native  StoreString     takes gamecache cache, string missionKey, string key, string value returns boolean]]>
    </Native>

    <Native Name="SyncStoredInteger" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native SyncStoredInteger        takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="SyncStoredReal" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native SyncStoredReal           takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="SyncStoredBoolean" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native SyncStoredBoolean        takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="SyncStoredUnit" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native SyncStoredUnit           takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="SyncStoredString" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native SyncStoredString         takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="GetStoredInteger" ReturnType="integer" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  GetStoredInteger        takes gamecache cache, string missionKey, string key returns integer]]>
    </Native>

    <Native Name="GetStoredReal" ReturnType="real" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  GetStoredReal           takes gamecache cache, string missionKey, string key returns real]]>
    </Native>

    <Native Name="GetStoredBoolean" ReturnType="boolean" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  GetStoredBoolean        takes gamecache cache, string missionKey, string key returns boolean]]>
    </Native>

    <Native Name="GetStoredString" ReturnType="string" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  GetStoredString         takes gamecache cache, string missionKey, string key returns string]]>
    </Native>

    <Native Name="RestoreUnit" ReturnType="unit" ArgumentList="gamecache cache, string missionKey, string key, player forWhichPlayer, real x, real y, real facing">
      <![CDATA[native  RestoreUnit             takes gamecache cache, string missionKey, string key, player forWhichPlayer, real x, real y, real facing returns unit]]>
    </Native>

    <Native Name="HaveStoredInteger" ReturnType="boolean" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  HaveStoredInteger        takes gamecache cache, string missionKey, string key returns boolean]]>
    </Native>

    <Native Name="HaveStoredReal" ReturnType="boolean" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  HaveStoredReal           takes gamecache cache, string missionKey, string key returns boolean]]>
    </Native>

    <Native Name="HaveStoredBoolean" ReturnType="boolean" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  HaveStoredBoolean        takes gamecache cache, string missionKey, string key returns boolean]]>
    </Native>

    <Native Name="HaveStoredUnit" ReturnType="boolean" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  HaveStoredUnit           takes gamecache cache, string missionKey, string key returns boolean]]>
    </Native>

    <Native Name="HaveStoredString" ReturnType="boolean" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  HaveStoredString         takes gamecache cache, string missionKey, string key returns boolean]]>
    </Native>

    <Native Name="FlushGameCache" ReturnType="nothing" ArgumentList="gamecache cache">
      <![CDATA[native  FlushGameCache          takes gamecache cache returns nothing]]>
    </Native>

    <Native Name="FlushStoredMission" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey">
      <![CDATA[native  FlushStoredMission      takes gamecache cache, string missionKey returns nothing]]>
    </Native>

    <Native Name="FlushStoredInteger" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  FlushStoredInteger      takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="FlushStoredReal" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  FlushStoredReal         takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="FlushStoredBoolean" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  FlushStoredBoolean      takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="FlushStoredUnit" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  FlushStoredUnit         takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="FlushStoredString" ReturnType="nothing" ArgumentList="gamecache cache, string missionKey, string key">
      <![CDATA[native  FlushStoredString       takes gamecache cache, string missionKey, string key returns nothing]]>
    </Native>

    <Native Name="GetRandomInt" ReturnType="integer" ArgumentList="integer lowBound, integer highBound">
      <![CDATA[native GetRandomInt takes integer lowBound, integer highBound returns integer]]>
    </Native>

    <Native Name="GetRandomReal" ReturnType="real" ArgumentList="real lowBound, real highBound">
      <![CDATA[native GetRandomReal takes real lowBound, real highBound returns real]]>
    </Native>

    <Native Name="CreateUnitPool" ReturnType="unitpool" ArgumentList="nothing">
      <![CDATA[native CreateUnitPool           takes nothing returns unitpool]]>
    </Native>

    <Native Name="DestroyUnitPool" ReturnType="nothing" ArgumentList="unitpool whichPool">
      <![CDATA[native DestroyUnitPool          takes unitpool whichPool returns nothing]]>
    </Native>

    <Native Name="UnitPoolAddUnitType" ReturnType="nothing" ArgumentList="unitpool whichPool, integer unitId, real weight">
      <![CDATA[native UnitPoolAddUnitType      takes unitpool whichPool, integer unitId, real weight returns nothing]]>
    </Native>

    <Native Name="UnitPoolRemoveUnitType" ReturnType="nothing" ArgumentList="unitpool whichPool, integer unitId">
      <![CDATA[native UnitPoolRemoveUnitType   takes unitpool whichPool, integer unitId returns nothing]]>
    </Native>

    <Native Name="PlaceRandomUnit" ReturnType="unit" ArgumentList="unitpool whichPool, player forWhichPlayer, real x, real y, real facing">
      <![CDATA[native PlaceRandomUnit          takes unitpool whichPool, player forWhichPlayer, real x, real y, real facing returns unit]]>
    </Native>

    <Native Name="CreateItemPool" ReturnType="itempool" ArgumentList="nothing">
      <![CDATA[native CreateItemPool           takes nothing returns itempool]]>
    </Native>

    <Native Name="DestroyItemPool" ReturnType="nothing" ArgumentList="itempool whichItemPool">
      <![CDATA[native DestroyItemPool          takes itempool whichItemPool returns nothing]]>
    </Native>

    <Native Name="ItemPoolAddItemType" ReturnType="nothing" ArgumentList="itempool whichItemPool, integer itemId, real weight">
      <![CDATA[native ItemPoolAddItemType      takes itempool whichItemPool, integer itemId, real weight returns nothing]]>
    </Native>

    <Native Name="ItemPoolRemoveItemType" ReturnType="nothing" ArgumentList="itempool whichItemPool, integer itemId">
      <![CDATA[native ItemPoolRemoveItemType   takes itempool whichItemPool, integer itemId returns nothing]]>
    </Native>

    <Native Name="PlaceRandomItem" ReturnType="item" ArgumentList="itempool whichItemPool, real x, real y">
      <![CDATA[native PlaceRandomItem          takes itempool whichItemPool, real x, real y returns item]]>
    </Native>

    <Native Name="ChooseRandomCreep" ReturnType="integer" ArgumentList="integer level">
      <![CDATA[native ChooseRandomCreep        takes integer level returns integer]]>
    </Native>

    <Native Name="ChooseRandomNPBuilding" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[native ChooseRandomNPBuilding   takes nothing returns integer]]>
    </Native>

    <Native Name="ChooseRandomItem" ReturnType="integer" ArgumentList="integer level">
      <![CDATA[native ChooseRandomItem         takes integer level returns integer]]>
    </Native>

    <Native Name="ChooseRandomItemEx" ReturnType="integer" ArgumentList="itemtype whichType, integer level">
      <![CDATA[native ChooseRandomItemEx       takes itemtype whichType, integer level returns integer]]>
    </Native>

    <Native Name="SetRandomSeed" ReturnType="nothing" ArgumentList="integer seed">
      <![CDATA[native SetRandomSeed            takes integer seed returns nothing]]>
    </Native>

    <Native Name="SetTerrainFog" ReturnType="nothing" ArgumentList="real a, real b, real c, real d, real e">
      <![CDATA[native SetTerrainFog                takes real a, real b, real c, real d, real e returns nothing]]>
    </Native>

    <Native Name="ResetTerrainFog" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native ResetTerrainFog              takes nothing returns nothing]]>
    </Native>

    <Native Name="SetUnitFog" ReturnType="nothing" ArgumentList="real a, real b, real c, real d, real e">
      <![CDATA[native SetUnitFog                   takes real a, real b, real c, real d, real e returns nothing]]>
    </Native>

    <Native Name="SetTerrainFogEx" ReturnType="nothing" ArgumentList="integer style, real zstart, real zend, real density, real red, real green, real blue">
      <![CDATA[native SetTerrainFogEx              takes integer style, real zstart, real zend, real density, real red, real green, real blue returns nothing]]>
    </Native>

    <Native Name="DisplayTextToPlayer" ReturnType="nothing" ArgumentList="player toPlayer, real x, real y, string message">
      <![CDATA[native DisplayTextToPlayer          takes player toPlayer, real x, real y, string message returns nothing]]>
    </Native>

    <Native Name="DisplayTimedTextToPlayer" ReturnType="nothing" ArgumentList="player toPlayer, real x, real y, real duration, string message">
      <![CDATA[native DisplayTimedTextToPlayer     takes player toPlayer, real x, real y, real duration, string message returns nothing]]>
    </Native>

    <Native Name="DisplayTimedTextFromPlayer" ReturnType="nothing" ArgumentList="player toPlayer, real x, real y, real duration, string message">
      <![CDATA[native DisplayTimedTextFromPlayer   takes player toPlayer, real x, real y, real duration, string message returns nothing]]>
    </Native>

    <Native Name="ClearTextMessages" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native ClearTextMessages            takes nothing returns nothing]]>
    </Native>

    <Native Name="SetDayNightModels" ReturnType="nothing" ArgumentList="string terrainDNCFile, string unitDNCFile">
      <![CDATA[native SetDayNightModels            takes string terrainDNCFile, string unitDNCFile returns nothing]]>
    </Native>

    <Native Name="SetSkyModel" ReturnType="nothing" ArgumentList="string skyModelFile">
      <![CDATA[native SetSkyModel                  takes string skyModelFile returns nothing]]>
    </Native>

    <Native Name="EnableUserControl" ReturnType="nothing" ArgumentList="boolean b">
      <![CDATA[native EnableUserControl            takes boolean b returns nothing]]>
    </Native>

    <Native Name="EnableUserUI" ReturnType="nothing" ArgumentList="boolean b">
      <![CDATA[native EnableUserUI                 takes boolean b returns nothing]]>
    </Native>

    <Native Name="SuspendTimeOfDay" ReturnType="nothing" ArgumentList="boolean b">
      <![CDATA[native SuspendTimeOfDay             takes boolean b returns nothing]]>
    </Native>

    <Native Name="SetTimeOfDayScale" ReturnType="nothing" ArgumentList="real r">
      <![CDATA[native SetTimeOfDayScale            takes real r returns nothing]]>
    </Native>

    <Native Name="GetTimeOfDayScale" ReturnType="real" ArgumentList="nothing">
      <![CDATA[native GetTimeOfDayScale            takes nothing returns real]]>
    </Native>

    <Native Name="ShowInterface" ReturnType="nothing" ArgumentList="boolean flag, real fadeDuration">
      <![CDATA[native ShowInterface                takes boolean flag, real fadeDuration returns nothing]]>
    </Native>

    <Native Name="PauseGame" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[native PauseGame                    takes boolean flag returns nothing]]>
    </Native>

    <Native Name="UnitAddIndicator" ReturnType="nothing" ArgumentList="unit whichUnit, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native UnitAddIndicator             takes unit whichUnit, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="AddIndicator" ReturnType="nothing" ArgumentList="widget whichWidget, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native AddIndicator                 takes widget whichWidget, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="PingMinimap" ReturnType="nothing" ArgumentList="real x, real y, real duration">
      <![CDATA[native PingMinimap                  takes real x, real y, real duration returns nothing]]>
    </Native>

    <Native Name="PingMinimapEx" ReturnType="nothing" ArgumentList="real x, real y, real duration, integer red, integer green, integer blue, boolean extraEffects">
      <![CDATA[native PingMinimapEx                takes real x, real y, real duration, integer red, integer green, integer blue, boolean extraEffects returns nothing]]>
    </Native>

    <Native Name="EnableOcclusion" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[native EnableOcclusion              takes boolean flag returns nothing]]>
    </Native>

    <Native Name="SetIntroShotText" ReturnType="nothing" ArgumentList="string introText">
      <![CDATA[native SetIntroShotText             takes string introText returns nothing]]>
    </Native>

    <Native Name="SetIntroShotModel" ReturnType="nothing" ArgumentList="string introModelPath">
      <![CDATA[native SetIntroShotModel            takes string introModelPath returns nothing]]>
    </Native>

    <Native Name="EnableWorldFogBoundary" ReturnType="nothing" ArgumentList="boolean b">
      <![CDATA[native EnableWorldFogBoundary       takes boolean b returns nothing]]>
    </Native>

    <Native Name="PlayModelCinematic" ReturnType="nothing" ArgumentList="string modelName">
      <![CDATA[native PlayModelCinematic           takes string modelName returns nothing]]>
    </Native>

    <Native Name="PlayCinematic" ReturnType="nothing" ArgumentList="string movieName">
      <![CDATA[native PlayCinematic                takes string movieName returns nothing]]>
    </Native>

    <Native Name="ForceUIKey" ReturnType="nothing" ArgumentList="string key">
      <![CDATA[native ForceUIKey                   takes string key returns nothing]]>
    </Native>

    <Native Name="ForceUICancel" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native ForceUICancel                takes nothing returns nothing]]>
    </Native>

    <Native Name="DisplayLoadDialog" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native DisplayLoadDialog            takes nothing returns nothing]]>
    </Native>

    <Native Name="SetAltMinimapIcon" ReturnType="nothing" ArgumentList="string iconPath">
      <![CDATA[native SetAltMinimapIcon            takes string iconPath returns nothing]]>
    </Native>

    <Native Name="DisableRestartMission" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[native DisableRestartMission        takes boolean flag returns nothing]]>
    </Native>

    <Native Name="CreateTextTag" ReturnType="texttag" ArgumentList="nothing">
      <![CDATA[native CreateTextTag                takes nothing returns texttag]]>
    </Native>

    <Native Name="DestroyTextTag" ReturnType="nothing" ArgumentList="texttag t">
      <![CDATA[native DestroyTextTag               takes texttag t returns nothing]]>
    </Native>

    <Native Name="SetTextTagText" ReturnType="nothing" ArgumentList="texttag t, string s, real height">
      <![CDATA[native SetTextTagText               takes texttag t, string s, real height returns nothing]]>
    </Native>

    <Native Name="SetTextTagPos" ReturnType="nothing" ArgumentList="texttag t, real x, real y, real heightOffset">
      <![CDATA[native SetTextTagPos                takes texttag t, real x, real y, real heightOffset returns nothing]]>
    </Native>

    <Native Name="SetTextTagPosUnit" ReturnType="nothing" ArgumentList="texttag t, unit whichUnit, real heightOffset">
      <![CDATA[native SetTextTagPosUnit            takes texttag t, unit whichUnit, real heightOffset returns nothing]]>
    </Native>

    <Native Name="SetTextTagColor" ReturnType="nothing" ArgumentList="texttag t, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native SetTextTagColor              takes texttag t, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="SetTextTagVelocity" ReturnType="nothing" ArgumentList="texttag t, real xvel, real yvel">
      <![CDATA[native SetTextTagVelocity           takes texttag t, real xvel, real yvel returns nothing]]>
    </Native>

    <Native Name="SetTextTagVisibility" ReturnType="nothing" ArgumentList="texttag t, boolean flag">
      <![CDATA[native SetTextTagVisibility         takes texttag t, boolean flag returns nothing]]>
    </Native>

    <Native Name="SetReservedLocalHeroButtons" ReturnType="nothing" ArgumentList="integer reserved">
      <![CDATA[native SetReservedLocalHeroButtons  takes integer reserved returns nothing]]>
    </Native>

    <Native Name="GetAllyColorFilterState" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[native GetAllyColorFilterState      takes nothing returns integer]]>
    </Native>

    <Native Name="SetAllyColorFilterState" ReturnType="nothing" ArgumentList="integer state">
      <![CDATA[native SetAllyColorFilterState      takes integer state returns nothing]]>
    </Native>

    <Native Name="CreateTrackable" ReturnType="trackable" ArgumentList="string trackableModelPath, real x, real y, real facing">
      <![CDATA[native CreateTrackable      takes string trackableModelPath, real x, real y, real facing returns trackable]]>
    </Native>

    <Native Name="CreateQuest" ReturnType="quest" ArgumentList="nothing">
      <![CDATA[native CreateQuest          takes nothing returns quest]]>
    </Native>

    <Native Name="DestroyQuest" ReturnType="nothing" ArgumentList="quest whichQuest">
      <![CDATA[native DestroyQuest         takes quest whichQuest returns nothing]]>
    </Native>

    <Native Name="QuestSetTitle" ReturnType="nothing" ArgumentList="quest whichQuest, string title">
      <![CDATA[native QuestSetTitle        takes quest whichQuest, string title returns nothing]]>
    </Native>

    <Native Name="QuestSetDescription" ReturnType="nothing" ArgumentList="quest whichQuest, string description">
      <![CDATA[native QuestSetDescription  takes quest whichQuest, string description returns nothing]]>
    </Native>

    <Native Name="QuestSetIconPath" ReturnType="nothing" ArgumentList="quest whichQuest, string iconPath">
      <![CDATA[native QuestSetIconPath     takes quest whichQuest, string iconPath returns nothing]]>
    </Native>

    <Native Name="QuestSetRequired" ReturnType="nothing" ArgumentList="quest whichQuest, boolean required">
      <![CDATA[native QuestSetRequired     takes quest whichQuest, boolean required   returns nothing]]>
    </Native>

    <Native Name="QuestSetCompleted" ReturnType="nothing" ArgumentList="quest whichQuest, boolean completed">
      <![CDATA[native QuestSetCompleted    takes quest whichQuest, boolean completed  returns nothing]]>
    </Native>

    <Native Name="QuestSetDiscovered" ReturnType="nothing" ArgumentList="quest whichQuest, boolean discovered">
      <![CDATA[native QuestSetDiscovered   takes quest whichQuest, boolean discovered returns nothing]]>
    </Native>

    <Native Name="QuestSetFailed" ReturnType="nothing" ArgumentList="quest whichQuest, boolean failed">
      <![CDATA[native QuestSetFailed       takes quest whichQuest, boolean failed     returns nothing]]>
    </Native>

    <Native Name="QuestSetEnabled" ReturnType="nothing" ArgumentList="quest whichQuest, boolean enabled">
      <![CDATA[native QuestSetEnabled      takes quest whichQuest, boolean enabled    returns nothing]]>
    </Native>

    <Native Name="IsQuestRequired" ReturnType="boolean" ArgumentList="quest whichQuest">
      <![CDATA[native IsQuestRequired     takes quest whichQuest returns boolean]]>
    </Native>

    <Native Name="IsQuestCompleted" ReturnType="boolean" ArgumentList="quest whichQuest">
      <![CDATA[native IsQuestCompleted    takes quest whichQuest returns boolean]]>
    </Native>

    <Native Name="IsQuestDiscovered" ReturnType="boolean" ArgumentList="quest whichQuest">
      <![CDATA[native IsQuestDiscovered   takes quest whichQuest returns boolean]]>
    </Native>

    <Native Name="IsQuestFailed" ReturnType="boolean" ArgumentList="quest whichQuest">
      <![CDATA[native IsQuestFailed       takes quest whichQuest returns boolean]]>
    </Native>

    <Native Name="IsQuestEnabled" ReturnType="boolean" ArgumentList="quest whichQuest">
      <![CDATA[native IsQuestEnabled      takes quest whichQuest returns boolean]]>
    </Native>

    <Native Name="QuestCreateItem" ReturnType="questitem" ArgumentList="quest whichQuest">
      <![CDATA[native QuestCreateItem          takes quest whichQuest returns questitem]]>
    </Native>

    <Native Name="QuestItemSetDescription" ReturnType="nothing" ArgumentList="questitem whichQuestItem, string description">
      <![CDATA[native QuestItemSetDescription  takes questitem whichQuestItem, string description returns nothing]]>
    </Native>

    <Native Name="QuestItemSetCompleted" ReturnType="nothing" ArgumentList="questitem whichQuestItem, boolean completed">
      <![CDATA[native QuestItemSetCompleted    takes questitem whichQuestItem, boolean completed returns nothing]]>
    </Native>

    <Native Name="IsQuestItemCompleted" ReturnType="boolean" ArgumentList="questitem whichQuestItem">
      <![CDATA[native IsQuestItemCompleted     takes questitem whichQuestItem returns boolean]]>
    </Native>

    <Native Name="CreateDefeatCondition" ReturnType="defeatcondition" ArgumentList="nothing">
      <![CDATA[native CreateDefeatCondition            takes nothing returns defeatcondition]]>
    </Native>

    <Native Name="DestroyDefeatCondition" ReturnType="nothing" ArgumentList="defeatcondition whichCondition">
      <![CDATA[native DestroyDefeatCondition           takes defeatcondition whichCondition returns nothing]]>
    </Native>

    <Native Name="DefeatConditionSetDescription" ReturnType="nothing" ArgumentList="defeatcondition whichCondition, string description">
      <![CDATA[native DefeatConditionSetDescription    takes defeatcondition whichCondition, string description returns nothing]]>
    </Native>

    <Native Name="FlashQuestDialogButton" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native FlashQuestDialogButton   takes nothing returns nothing]]>
    </Native>

    <Native Name="ForceQuestDialogUpdate" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native ForceQuestDialogUpdate   takes nothing returns nothing]]>
    </Native>

    <Native Name="CreateTimerDialog" ReturnType="timerdialog" ArgumentList="timer t">
      <![CDATA[native CreateTimerDialog                takes timer t returns timerdialog]]>
    </Native>

    <Native Name="DestroyTimerDialog" ReturnType="nothing" ArgumentList="timerdialog whichDialog">
      <![CDATA[native DestroyTimerDialog               takes timerdialog whichDialog returns nothing]]>
    </Native>

    <Native Name="TimerDialogSetTitle" ReturnType="nothing" ArgumentList="timerdialog whichDialog, string title">
      <![CDATA[native TimerDialogSetTitle              takes timerdialog whichDialog, string title returns nothing]]>
    </Native>

    <Native Name="TimerDialogSetTitleColor" ReturnType="nothing" ArgumentList="timerdialog whichDialog, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native TimerDialogSetTitleColor         takes timerdialog whichDialog, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="TimerDialogSetTimeColor" ReturnType="nothing" ArgumentList="timerdialog whichDialog, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native TimerDialogSetTimeColor          takes timerdialog whichDialog, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="TimerDialogSetSpeed" ReturnType="nothing" ArgumentList="timerdialog whichDialog, real speedMultFactor">
      <![CDATA[native TimerDialogSetSpeed              takes timerdialog whichDialog, real speedMultFactor returns nothing]]>
    </Native>

    <Native Name="TimerDialogDisplay" ReturnType="nothing" ArgumentList="timerdialog whichDialog, boolean display">
      <![CDATA[native TimerDialogDisplay               takes timerdialog whichDialog, boolean display returns nothing]]>
    </Native>

    <Native Name="IsTimerDialogDisplayed" ReturnType="boolean" ArgumentList="timerdialog whichDialog">
      <![CDATA[native IsTimerDialogDisplayed           takes timerdialog whichDialog returns boolean]]>
    </Native>

    <Native Name="TimerDialogSetRealTimeRemaining" ReturnType="nothing" ArgumentList="timerdialog whichDialog, real timeRemaining">
      <![CDATA[native TimerDialogSetRealTimeRemaining  takes timerdialog whichDialog, real timeRemaining returns nothing]]>
    </Native>

    <Native Name="CreateLeaderboard" ReturnType="leaderboard" ArgumentList="nothing">
      <![CDATA[native CreateLeaderboard                takes nothing returns leaderboard]]>
    </Native>

    <Native Name="DestroyLeaderboard" ReturnType="nothing" ArgumentList="leaderboard lb">
      <![CDATA[native DestroyLeaderboard               takes leaderboard lb returns nothing]]>
    </Native>

    <Native Name="LeaderboardDisplay" ReturnType="nothing" ArgumentList="leaderboard lb, boolean show">
      <![CDATA[native LeaderboardDisplay               takes leaderboard lb, boolean show returns nothing]]>
    </Native>

    <Native Name="IsLeaderboardDisplayed" ReturnType="boolean" ArgumentList="leaderboard lb">
      <![CDATA[native IsLeaderboardDisplayed           takes leaderboard lb returns boolean]]>
    </Native>

    <Native Name="LeaderboardGetItemCount" ReturnType="integer" ArgumentList="leaderboard lb">
      <![CDATA[native LeaderboardGetItemCount          takes leaderboard lb returns integer]]>
    </Native>

    <Native Name="LeaderboardSetSizeByItemCount" ReturnType="nothing" ArgumentList="leaderboard lb, integer count">
      <![CDATA[native LeaderboardSetSizeByItemCount    takes leaderboard lb, integer count returns nothing]]>
    </Native>

    <Native Name="LeaderboardAddItem" ReturnType="nothing" ArgumentList="leaderboard lb, string label, integer value, player p">
      <![CDATA[native LeaderboardAddItem               takes leaderboard lb, string label, integer value, player p returns nothing]]>
    </Native>

    <Native Name="LeaderboardRemoveItem" ReturnType="nothing" ArgumentList="leaderboard lb, integer index">
      <![CDATA[native LeaderboardRemoveItem            takes leaderboard lb, integer index returns nothing]]>
    </Native>

    <Native Name="LeaderboardRemovePlayerItem" ReturnType="nothing" ArgumentList="leaderboard lb, player p">
      <![CDATA[native LeaderboardRemovePlayerItem      takes leaderboard lb, player p returns nothing]]>
    </Native>

    <Native Name="LeaderboardClear" ReturnType="nothing" ArgumentList="leaderboard lb">
      <![CDATA[native LeaderboardClear                 takes leaderboard lb returns nothing]]>
    </Native>

    <Native Name="LeaderboardSortItemsByValue" ReturnType="nothing" ArgumentList="leaderboard lb, boolean ascending">
      <![CDATA[native LeaderboardSortItemsByValue      takes leaderboard lb, boolean ascending returns nothing]]>
    </Native>

    <Native Name="LeaderboardSortItemsByPlayer" ReturnType="nothing" ArgumentList="leaderboard lb, boolean ascending">
      <![CDATA[native LeaderboardSortItemsByPlayer     takes leaderboard lb, boolean ascending returns nothing]]>
    </Native>

    <Native Name="LeaderboardSortItemsByLabel" ReturnType="nothing" ArgumentList="leaderboard lb, boolean ascending">
      <![CDATA[native LeaderboardSortItemsByLabel      takes leaderboard lb, boolean ascending returns nothing]]>
    </Native>

    <Native Name="LeaderboardHasPlayerItem" ReturnType="boolean" ArgumentList="leaderboard lb, player p">
      <![CDATA[native LeaderboardHasPlayerItem         takes leaderboard lb, player p returns boolean]]>
    </Native>

    <Native Name="LeaderboardGetPlayerIndex" ReturnType="integer" ArgumentList="leaderboard lb, player p">
      <![CDATA[native LeaderboardGetPlayerIndex        takes leaderboard lb, player p returns integer]]>
    </Native>

    <Native Name="LeaderboardSetLabel" ReturnType="nothing" ArgumentList="leaderboard lb, string label">
      <![CDATA[native LeaderboardSetLabel              takes leaderboard lb, string label returns nothing]]>
    </Native>

    <Native Name="LeaderboardGetLabelText" ReturnType="string" ArgumentList="leaderboard lb">
      <![CDATA[native LeaderboardGetLabelText          takes leaderboard lb returns string]]>
    </Native>

    <Native Name="PlayerSetLeaderboard" ReturnType="nothing" ArgumentList="player toPlayer, leaderboard lb">
      <![CDATA[native PlayerSetLeaderboard             takes player toPlayer, leaderboard lb returns nothing]]>
    </Native>

    <Native Name="PlayerGetLeaderboard" ReturnType="leaderboard" ArgumentList="player toPlayer">
      <![CDATA[native PlayerGetLeaderboard             takes player toPlayer returns leaderboard]]>
    </Native>

    <Native Name="LeaderboardSetLabelColor" ReturnType="nothing" ArgumentList="leaderboard lb, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native LeaderboardSetLabelColor         takes leaderboard lb, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="LeaderboardSetValueColor" ReturnType="nothing" ArgumentList="leaderboard lb, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native LeaderboardSetValueColor         takes leaderboard lb, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="LeaderboardSetStyle" ReturnType="nothing" ArgumentList="leaderboard lb, boolean showLabel, boolean showNames, boolean showValues, boolean showIcons">
      <![CDATA[native LeaderboardSetStyle              takes leaderboard lb, boolean showLabel, boolean showNames, boolean showValues, boolean showIcons returns nothing]]>
    </Native>

    <Native Name="LeaderboardSetItemValue" ReturnType="nothing" ArgumentList="leaderboard lb, integer whichItem, integer val">
      <![CDATA[native LeaderboardSetItemValue          takes leaderboard lb, integer whichItem, integer val returns nothing]]>
    </Native>

    <Native Name="LeaderboardSetItemLabel" ReturnType="nothing" ArgumentList="leaderboard lb, integer whichItem, string val">
      <![CDATA[native LeaderboardSetItemLabel          takes leaderboard lb, integer whichItem, string val returns nothing]]>
    </Native>

    <Native Name="LeaderboardSetItemStyle" ReturnType="nothing" ArgumentList="leaderboard lb, integer whichItem, boolean showLabel, boolean showValue, boolean showIcon">
      <![CDATA[native LeaderboardSetItemStyle          takes leaderboard lb, integer whichItem, boolean showLabel, boolean showValue, boolean showIcon returns nothing]]>
    </Native>

    <Native Name="LeaderboardSetItemLabelColor" ReturnType="nothing" ArgumentList="leaderboard lb, integer whichItem, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native LeaderboardSetItemLabelColor     takes leaderboard lb, integer whichItem, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="LeaderboardSetItemValueColor" ReturnType="nothing" ArgumentList="leaderboard lb, integer whichItem, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native LeaderboardSetItemValueColor     takes leaderboard lb, integer whichItem, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="CreateMultiboard" ReturnType="multiboard" ArgumentList="nothing">
      <![CDATA[native CreateMultiboard                 takes nothing returns multiboard]]>
    </Native>

    <Native Name="DestroyMultiboard" ReturnType="nothing" ArgumentList="multiboard lb">
      <![CDATA[native DestroyMultiboard                takes multiboard lb returns nothing]]>
    </Native>

    <Native Name="MultiboardDisplay" ReturnType="nothing" ArgumentList="multiboard lb, boolean show">
      <![CDATA[native MultiboardDisplay                takes multiboard lb, boolean show returns nothing]]>
    </Native>

    <Native Name="IsMultiboardDisplayed" ReturnType="boolean" ArgumentList="multiboard lb">
      <![CDATA[native IsMultiboardDisplayed            takes multiboard lb returns boolean]]>
    </Native>

    <Native Name="MultiboardMinimize" ReturnType="nothing" ArgumentList="multiboard lb, boolean minimize">
      <![CDATA[native MultiboardMinimize               takes multiboard lb, boolean minimize returns nothing]]>
    </Native>

    <Native Name="IsMultiboardMinimized" ReturnType="boolean" ArgumentList="multiboard lb">
      <![CDATA[native IsMultiboardMinimized            takes multiboard lb returns boolean]]>
    </Native>

    <Native Name="MultiboardClear" ReturnType="nothing" ArgumentList="multiboard lb">
      <![CDATA[native MultiboardClear                  takes multiboard lb returns nothing]]>
    </Native>

    <Native Name="MultiboardSetTitleText" ReturnType="nothing" ArgumentList="multiboard lb, string label">
      <![CDATA[native MultiboardSetTitleText           takes multiboard lb, string label returns nothing]]>
    </Native>

    <Native Name="MultiboardGetTitleText" ReturnType="string" ArgumentList="multiboard lb">
      <![CDATA[native MultiboardGetTitleText           takes multiboard lb returns string]]>
    </Native>

    <Native Name="MultiboardSetTitleTextColor" ReturnType="nothing" ArgumentList="multiboard lb, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native MultiboardSetTitleTextColor      takes multiboard lb, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="MultiboardGetRowCount" ReturnType="integer" ArgumentList="multiboard lb">
      <![CDATA[native MultiboardGetRowCount            takes multiboard lb returns integer]]>
    </Native>

    <Native Name="MultiboardGetColumnCount" ReturnType="integer" ArgumentList="multiboard lb">
      <![CDATA[native MultiboardGetColumnCount         takes multiboard lb returns integer]]>
    </Native>

    <Native Name="MultiboardSetColumnCount" ReturnType="nothing" ArgumentList="multiboard lb, integer count">
      <![CDATA[native MultiboardSetColumnCount         takes multiboard lb, integer count returns nothing]]>
    </Native>

    <Native Name="MultiboardSetRowCount" ReturnType="nothing" ArgumentList="multiboard lb, integer count">
      <![CDATA[native MultiboardSetRowCount            takes multiboard lb, integer count returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemsStyle" ReturnType="nothing" ArgumentList="multiboard lb, boolean showValues, boolean showIcons">
      <![CDATA[native MultiboardSetItemsStyle          takes multiboard lb, boolean showValues, boolean showIcons returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemsValue" ReturnType="nothing" ArgumentList="multiboard lb, string value">
      <![CDATA[native MultiboardSetItemsValue          takes multiboard lb, string value returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemsValueColor" ReturnType="nothing" ArgumentList="multiboard lb, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native MultiboardSetItemsValueColor     takes multiboard lb, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemsWidth" ReturnType="nothing" ArgumentList="multiboard lb, real width">
      <![CDATA[native MultiboardSetItemsWidth          takes multiboard lb, real width returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemsIcon" ReturnType="nothing" ArgumentList="multiboard lb, string iconPath">
      <![CDATA[native MultiboardSetItemsIcon           takes multiboard lb, string iconPath returns nothing]]>
    </Native>

    <Native Name="MultiboardGetItem" ReturnType="multiboarditem" ArgumentList="multiboard lb, integer row, integer column">
      <![CDATA[native MultiboardGetItem                takes multiboard lb, integer row, integer column returns multiboarditem]]>
    </Native>

    <Native Name="MultiboardReleaseItem" ReturnType="nothing" ArgumentList="multiboarditem mbi">
      <![CDATA[native MultiboardReleaseItem            takes multiboarditem mbi returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemStyle" ReturnType="nothing" ArgumentList="multiboarditem mbi, boolean showValue, boolean showIcon">
      <![CDATA[native MultiboardSetItemStyle           takes multiboarditem mbi, boolean showValue, boolean showIcon returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemValue" ReturnType="nothing" ArgumentList="multiboarditem mbi, string val">
      <![CDATA[native MultiboardSetItemValue           takes multiboarditem mbi, string val returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemValueColor" ReturnType="nothing" ArgumentList="multiboarditem mbi, integer red, integer green, integer blue, integer alpha">
      <![CDATA[native MultiboardSetItemValueColor      takes multiboarditem mbi, integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemWidth" ReturnType="nothing" ArgumentList="multiboarditem mbi, real width">
      <![CDATA[native MultiboardSetItemWidth           takes multiboarditem mbi, real width returns nothing]]>
    </Native>

    <Native Name="MultiboardSetItemIcon" ReturnType="nothing" ArgumentList="multiboarditem mbi, string iconFileName">
      <![CDATA[native MultiboardSetItemIcon            takes multiboarditem mbi, string iconFileName returns nothing]]>
    </Native>

    <Native Name="MultiboardSuppressDisplay" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[native MultiboardSuppressDisplay        takes boolean flag returns nothing]]>
    </Native>

    <Native Name="SetCameraPosition" ReturnType="nothing" ArgumentList="real x, real y">
      <![CDATA[native SetCameraPosition            takes real x, real y returns nothing]]>
    </Native>

    <Native Name="SetCameraQuickPosition" ReturnType="nothing" ArgumentList="real x, real y">
      <![CDATA[native SetCameraQuickPosition       takes real x, real y returns nothing]]>
    </Native>

    <Native Name="SetCameraBounds" ReturnType="nothing" ArgumentList="real x1, real y1, real x2, real y2, real x3, real y3, real x4, real y4">
      <![CDATA[native SetCameraBounds              takes real x1, real y1, real x2, real y2, real x3, real y3, real x4, real y4 returns nothing]]>
    </Native>

    <Native Name="StopCamera" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native StopCamera                   takes nothing returns nothing]]>
    </Native>

    <Native Name="ResetToGameCamera" ReturnType="nothing" ArgumentList="real duration">
      <![CDATA[native ResetToGameCamera            takes real duration returns nothing]]>
    </Native>

    <Native Name="PanCameraTo" ReturnType="nothing" ArgumentList="real x, real y">
      <![CDATA[native PanCameraTo                  takes real x, real y returns nothing]]>
    </Native>

    <Native Name="PanCameraToTimed" ReturnType="nothing" ArgumentList="real x, real y, real duration">
      <![CDATA[native PanCameraToTimed             takes real x, real y, real duration returns nothing]]>
    </Native>

    <Native Name="PanCameraToWithZ" ReturnType="nothing" ArgumentList="real x, real y, real zOffsetDest">
      <![CDATA[native PanCameraToWithZ             takes real x, real y, real zOffsetDest returns nothing]]>
    </Native>

    <Native Name="PanCameraToTimedWithZ" ReturnType="nothing" ArgumentList="real x, real y, real zOffsetDest, real duration">
      <![CDATA[native PanCameraToTimedWithZ        takes real x, real y, real zOffsetDest, real duration returns nothing]]>
    </Native>

    <Native Name="SetCinematicCamera" ReturnType="nothing" ArgumentList="string cameraModelFile">
      <![CDATA[native SetCinematicCamera           takes string cameraModelFile returns nothing]]>
    </Native>

    <Native Name="SetCameraRotateMode" ReturnType="nothing" ArgumentList="real x, real y, real radiansToSweep, real duration">
      <![CDATA[native SetCameraRotateMode          takes real x, real y, real radiansToSweep, real duration returns nothing]]>
    </Native>

    <Native Name="SetCameraField" ReturnType="nothing" ArgumentList="camerafield whichField, real value, real duration">
      <![CDATA[native SetCameraField               takes camerafield whichField, real value, real duration returns nothing]]>
    </Native>

    <Native Name="AdjustCameraField" ReturnType="nothing" ArgumentList="camerafield whichField, real offset, real duration">
      <![CDATA[native AdjustCameraField            takes camerafield whichField, real offset, real duration returns nothing]]>
    </Native>

    <Native Name="SetCameraTargetController" ReturnType="nothing" ArgumentList="unit whichUnit, real xoffset, real yoffset, boolean inheritOrientation">
      <![CDATA[native SetCameraTargetController    takes unit whichUnit, real xoffset, real yoffset, boolean inheritOrientation returns nothing]]>
    </Native>

    <Native Name="SetCameraOrientController" ReturnType="nothing" ArgumentList="unit whichUnit, real xoffset, real yoffset">
      <![CDATA[native SetCameraOrientController    takes unit whichUnit, real xoffset, real yoffset returns nothing]]>
    </Native>

    <Native Name="CreateCameraSetup" ReturnType="camerasetup" ArgumentList="nothing">
      <![CDATA[native CreateCameraSetup                    takes nothing returns camerasetup]]>
    </Native>

    <Native Name="CameraSetupSetField" ReturnType="nothing" ArgumentList="camerasetup whichSetup, camerafield whichField, real value, real duration">
      <![CDATA[native CameraSetupSetField                  takes camerasetup whichSetup, camerafield whichField, real value, real duration returns nothing]]>
    </Native>

    <Native Name="CameraSetupGetField" ReturnType="real" ArgumentList="camerasetup whichSetup, camerafield whichField">
      <![CDATA[native CameraSetupGetField                  takes camerasetup whichSetup, camerafield whichField returns real]]>
    </Native>

    <Native Name="CameraSetupSetDestPosition" ReturnType="nothing" ArgumentList="camerasetup whichSetup, real x, real y, real duration">
      <![CDATA[native CameraSetupSetDestPosition           takes camerasetup whichSetup, real x, real y, real duration returns nothing]]>
    </Native>

    <Native Name="CameraSetupGetDestPositionLoc" ReturnType="location" ArgumentList="camerasetup whichSetup">
      <![CDATA[native CameraSetupGetDestPositionLoc        takes camerasetup whichSetup returns location]]>
    </Native>

    <Native Name="CameraSetupGetDestPositionX" ReturnType="real" ArgumentList="camerasetup whichSetup">
      <![CDATA[native CameraSetupGetDestPositionX          takes camerasetup whichSetup returns real]]>
    </Native>

    <Native Name="CameraSetupGetDestPositionY" ReturnType="real" ArgumentList="camerasetup whichSetup">
      <![CDATA[native CameraSetupGetDestPositionY          takes camerasetup whichSetup returns real]]>
    </Native>

    <Native Name="CameraSetupApply" ReturnType="nothing" ArgumentList="camerasetup whichSetup, boolean doPan, boolean panTimed">
      <![CDATA[native CameraSetupApply                     takes camerasetup whichSetup, boolean doPan, boolean panTimed returns nothing]]>
    </Native>

    <Native Name="CameraSetupApplyWithZ" ReturnType="nothing" ArgumentList="camerasetup whichSetup, real zDestOffset">
      <![CDATA[native CameraSetupApplyWithZ                takes camerasetup whichSetup, real zDestOffset returns nothing]]>
    </Native>

    <Native Name="CameraSetupApplyForceDuration" ReturnType="nothing" ArgumentList="camerasetup whichSetup, boolean doPan, real forceDuration">
      <![CDATA[native CameraSetupApplyForceDuration        takes camerasetup whichSetup, boolean doPan, real forceDuration returns nothing]]>
    </Native>

    <Native Name="CameraSetupApplyForceDurationWithZ" ReturnType="nothing" ArgumentList="camerasetup whichSetup, real zDestOffset, real forceDuration">
      <![CDATA[native CameraSetupApplyForceDurationWithZ   takes camerasetup whichSetup, real zDestOffset, real forceDuration returns nothing]]>
    </Native>

    <Native Name="CameraSetTargetNoise" ReturnType="nothing" ArgumentList="real mag, real velocity">
      <![CDATA[native CameraSetTargetNoise             takes real mag, real velocity returns nothing]]>
    </Native>

    <Native Name="CameraSetSourceNoise" ReturnType="nothing" ArgumentList="real mag, real velocity">
      <![CDATA[native CameraSetSourceNoise             takes real mag, real velocity returns nothing]]>
    </Native>

    <Native Name="CameraSetTargetNoiseEx" ReturnType="nothing" ArgumentList="real mag, real velocity, boolean vertOnly">
      <![CDATA[native CameraSetTargetNoiseEx           takes real mag, real velocity, boolean vertOnly returns nothing]]>
    </Native>

    <Native Name="CameraSetSourceNoiseEx" ReturnType="nothing" ArgumentList="real mag, real velocity, boolean vertOnly">
      <![CDATA[native CameraSetSourceNoiseEx           takes real mag, real velocity, boolean vertOnly returns nothing]]>
    </Native>

    <Native Name="CameraSetSmoothingFactor" ReturnType="nothing" ArgumentList="real factor">
      <![CDATA[native CameraSetSmoothingFactor         takes real factor returns nothing]]>
    </Native>

    <Native Name="SetCineFilterTexture" ReturnType="nothing" ArgumentList="string filename">
      <![CDATA[native SetCineFilterTexture             takes string filename returns nothing]]>
    </Native>

    <Native Name="SetCineFilterBlendMode" ReturnType="nothing" ArgumentList="blendmode whichMode">
      <![CDATA[native SetCineFilterBlendMode           takes blendmode whichMode returns nothing]]>
    </Native>

    <Native Name="SetCineFilterTexMapFlags" ReturnType="nothing" ArgumentList="texmapflags whichFlags">
      <![CDATA[native SetCineFilterTexMapFlags         takes texmapflags whichFlags returns nothing]]>
    </Native>

    <Native Name="SetCineFilterStartUV" ReturnType="nothing" ArgumentList="real minu, real minv, real maxu, real maxv">
      <![CDATA[native SetCineFilterStartUV             takes real minu, real minv, real maxu, real maxv returns nothing]]>
    </Native>

    <Native Name="SetCineFilterEndUV" ReturnType="nothing" ArgumentList="real minu, real minv, real maxu, real maxv">
      <![CDATA[native SetCineFilterEndUV               takes real minu, real minv, real maxu, real maxv returns nothing]]>
    </Native>

    <Native Name="SetCineFilterStartColor" ReturnType="nothing" ArgumentList="integer red, integer green, integer blue, integer alpha">
      <![CDATA[native SetCineFilterStartColor          takes integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="SetCineFilterEndColor" ReturnType="nothing" ArgumentList="integer red, integer green, integer blue, integer alpha">
      <![CDATA[native SetCineFilterEndColor            takes integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="SetCineFilterDuration" ReturnType="nothing" ArgumentList="real duration">
      <![CDATA[native SetCineFilterDuration            takes real duration returns nothing]]>
    </Native>

    <Native Name="DisplayCineFilter" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[native DisplayCineFilter                takes boolean flag returns nothing]]>
    </Native>

    <Native Name="IsCineFilterDisplayed" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[native IsCineFilterDisplayed            takes nothing returns boolean]]>
    </Native>

    <Native Name="SetCinematicScene" ReturnType="nothing" ArgumentList="integer portraitUnitId, playercolor color, string speakerTitle, string text, real sceneDuration, real voiceoverDuration">
      <![CDATA[native SetCinematicScene                takes integer portraitUnitId, playercolor color, string speakerTitle, string text, real sceneDuration, real voiceoverDuration returns nothing]]>
    </Native>

    <Native Name="EndCinematicScene" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native EndCinematicScene                takes nothing returns nothing]]>
    </Native>

    <Native Name="ForceCinematicSubtitles" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[native ForceCinematicSubtitles          takes boolean flag returns nothing]]>
    </Native>

    <Native Name="GetCameraMargin" ReturnType="real" ArgumentList="integer whichMargin">
      <![CDATA[native GetCameraMargin                  takes integer whichMargin returns real]]>
    </Native>

    <Native Name="GetCameraBoundMinX" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraBoundMinX          takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraBoundMinY" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraBoundMinY          takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraBoundMaxX" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraBoundMaxX          takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraBoundMaxY" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraBoundMaxY          takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraField" ReturnType="real" ArgumentList="camerafield whichField">
      <![CDATA[constant native GetCameraField              takes camerafield whichField returns real]]>
    </Native>

    <Native Name="GetCameraTargetPositionX" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraTargetPositionX    takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraTargetPositionY" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraTargetPositionY    takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraTargetPositionZ" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraTargetPositionZ    takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraTargetPositionLoc" ReturnType="location" ArgumentList="nothing">
      <![CDATA[constant native GetCameraTargetPositionLoc  takes nothing returns location]]>
    </Native>

    <Native Name="GetCameraEyePositionX" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraEyePositionX       takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraEyePositionY" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraEyePositionY       takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraEyePositionZ" ReturnType="real" ArgumentList="nothing">
      <![CDATA[constant native GetCameraEyePositionZ       takes nothing returns real]]>
    </Native>

    <Native Name="GetCameraEyePositionLoc" ReturnType="location" ArgumentList="nothing">
      <![CDATA[constant native GetCameraEyePositionLoc     takes nothing returns location]]>
    </Native>

    <Native Name="NewSoundEnvironment" ReturnType="nothing" ArgumentList="string environmentName">
      <![CDATA[native NewSoundEnvironment          takes string environmentName returns nothing]]>
    </Native>

    <Native Name="CreateSound" ReturnType="sound" ArgumentList="string fileName, boolean looping, boolean is3D, boolean stopwhenoutofrange, integer fadeInRate, integer fadeOutRate, string eaxSetting">
      <![CDATA[native CreateSound                  takes string fileName, boolean looping, boolean is3D, boolean stopwhenoutofrange, integer fadeInRate, integer fadeOutRate, string eaxSetting returns sound]]>
    </Native>

    <Native Name="CreateSoundFilenameWithLabel" ReturnType="sound" ArgumentList="string fileName, boolean looping, boolean is3D, boolean stopwhenoutofrange, integer fadeInRate, integer fadeOutRate, string SLKEntryName">
      <![CDATA[native CreateSoundFilenameWithLabel takes string fileName, boolean looping, boolean is3D, boolean stopwhenoutofrange, integer fadeInRate, integer fadeOutRate, string SLKEntryName returns sound]]>
    </Native>

    <Native Name="CreateSoundFromLabel" ReturnType="sound" ArgumentList="string soundLabel, boolean looping, boolean is3D, boolean stopwhenoutofrange, integer fadeInRate, integer fadeOutRate">
      <![CDATA[native CreateSoundFromLabel         takes string soundLabel, boolean looping, boolean is3D, boolean stopwhenoutofrange, integer fadeInRate, integer fadeOutRate returns sound]]>
    </Native>

    <Native Name="CreateMIDISound" ReturnType="sound" ArgumentList="string soundLabel, integer fadeInRate, integer fadeOutRate">
      <![CDATA[native CreateMIDISound              takes string soundLabel, integer fadeInRate, integer fadeOutRate returns sound]]>
    </Native>

    <Native Name="SetSoundParamsFromLabel" ReturnType="nothing" ArgumentList="sound soundHandle, string soundLabel">
      <![CDATA[native SetSoundParamsFromLabel      takes sound soundHandle, string soundLabel returns nothing]]>
    </Native>

    <Native Name="SetSoundDistanceCutoff" ReturnType="nothing" ArgumentList="sound soundHandle, real cutoff">
      <![CDATA[native SetSoundDistanceCutoff       takes sound soundHandle, real cutoff returns nothing]]>
    </Native>

    <Native Name="SetSoundChannel" ReturnType="nothing" ArgumentList="sound soundHandle, integer channel">
      <![CDATA[native SetSoundChannel              takes sound soundHandle, integer channel returns nothing]]>
    </Native>

    <Native Name="SetSoundVolume" ReturnType="nothing" ArgumentList="sound soundHandle, integer volume">
      <![CDATA[native SetSoundVolume               takes sound soundHandle, integer volume returns nothing]]>
    </Native>

    <Native Name="SetSoundPitch" ReturnType="nothing" ArgumentList="sound soundHandle, real pitch">
      <![CDATA[native SetSoundPitch                takes sound soundHandle, real pitch returns nothing]]>
    </Native>

    <Native Name="SetSoundPlayPosition" ReturnType="nothing" ArgumentList="sound soundHandle, integer millisecs">
      <![CDATA[native SetSoundPlayPosition         takes sound soundHandle, integer millisecs returns nothing]]>
    </Native>

    <Native Name="SetSoundDistances" ReturnType="nothing" ArgumentList="sound soundHandle, real minDist, real maxDist">
      <![CDATA[native SetSoundDistances            takes sound soundHandle, real minDist, real maxDist returns nothing]]>
    </Native>

    <Native Name="SetSoundConeAngles" ReturnType="nothing" ArgumentList="sound soundHandle, real inside, real outside, integer outsideVolume">
      <![CDATA[native SetSoundConeAngles           takes sound soundHandle, real inside, real outside, integer outsideVolume returns nothing]]>
    </Native>

    <Native Name="SetSoundConeOrientation" ReturnType="nothing" ArgumentList="sound soundHandle, real x, real y, real z">
      <![CDATA[native SetSoundConeOrientation      takes sound soundHandle, real x, real y, real z returns nothing]]>
    </Native>

    <Native Name="SetSoundPosition" ReturnType="nothing" ArgumentList="sound soundHandle, real x, real y, real z">
      <![CDATA[native SetSoundPosition             takes sound soundHandle, real x, real y, real z returns nothing]]>
    </Native>

    <Native Name="SetSoundVelocity" ReturnType="nothing" ArgumentList="sound soundHandle, real x, real y, real z">
      <![CDATA[native SetSoundVelocity             takes sound soundHandle, real x, real y, real z returns nothing]]>
    </Native>

    <Native Name="AttachSoundToUnit" ReturnType="nothing" ArgumentList="sound soundHandle, unit whichUnit">
      <![CDATA[native AttachSoundToUnit            takes sound soundHandle, unit whichUnit returns nothing]]>
    </Native>

    <Native Name="StartSound" ReturnType="nothing" ArgumentList="sound soundHandle">
      <![CDATA[native StartSound                   takes sound soundHandle returns nothing]]>
    </Native>

    <Native Name="StopSound" ReturnType="nothing" ArgumentList="sound soundHandle, boolean killWhenDone, boolean fadeOut">
      <![CDATA[native StopSound                    takes sound soundHandle, boolean killWhenDone, boolean fadeOut returns nothing]]>
    </Native>

    <Native Name="KillSoundWhenDone" ReturnType="nothing" ArgumentList="sound soundHandle">
      <![CDATA[native KillSoundWhenDone            takes sound soundHandle returns nothing]]>
    </Native>

    <Native Name="SetMapMusic" ReturnType="nothing" ArgumentList="string musicName, boolean random, integer index">
      <![CDATA[native SetMapMusic                  takes string musicName, boolean random, integer index returns nothing]]>
    </Native>

    <Native Name="ClearMapMusic" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native ClearMapMusic                takes nothing returns nothing]]>
    </Native>

    <Native Name="PlayMusic" ReturnType="nothing" ArgumentList="string musicName">
      <![CDATA[native PlayMusic                    takes string musicName returns nothing]]>
    </Native>

    <Native Name="PlayMusicEx" ReturnType="nothing" ArgumentList="string musicName, integer frommsecs, integer fadeinmsecs">
      <![CDATA[native PlayMusicEx                  takes string musicName, integer frommsecs, integer fadeinmsecs returns nothing]]>
    </Native>

    <Native Name="StopMusic" ReturnType="nothing" ArgumentList="boolean fadeOut">
      <![CDATA[native StopMusic                    takes boolean fadeOut returns nothing]]>
    </Native>

    <Native Name="ResumeMusic" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native ResumeMusic                  takes nothing returns nothing]]>
    </Native>

    <Native Name="PlayThematicMusic" ReturnType="nothing" ArgumentList="string musicFileName">
      <![CDATA[native PlayThematicMusic            takes string musicFileName returns nothing]]>
    </Native>

    <Native Name="PlayThematicMusicEx" ReturnType="nothing" ArgumentList="string musicFileName, integer frommsecs">
      <![CDATA[native PlayThematicMusicEx          takes string musicFileName, integer frommsecs returns nothing]]>
    </Native>

    <Native Name="EndThematicMusic" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native EndThematicMusic             takes nothing returns nothing]]>
    </Native>

    <Native Name="SetMusicVolume" ReturnType="nothing" ArgumentList="integer volume">
      <![CDATA[native SetMusicVolume               takes integer volume returns nothing]]>
    </Native>

    <Native Name="SetMusicPlayPosition" ReturnType="nothing" ArgumentList="integer millisecs">
      <![CDATA[native SetMusicPlayPosition         takes integer millisecs returns nothing]]>
    </Native>

    <Native Name="SetThematicMusicPlayPosition" ReturnType="nothing" ArgumentList="integer millisecs">
      <![CDATA[native SetThematicMusicPlayPosition takes integer millisecs returns nothing]]>
    </Native>

    <Native Name="SetSoundDuration" ReturnType="nothing" ArgumentList="sound soundHandle, integer duration">
      <![CDATA[native SetSoundDuration             takes sound soundHandle, integer duration returns nothing]]>
    </Native>

    <Native Name="GetSoundDuration" ReturnType="integer" ArgumentList="sound soundHandle">
      <![CDATA[native GetSoundDuration             takes sound soundHandle returns integer]]>
    </Native>

    <Native Name="GetSoundFileDuration" ReturnType="integer" ArgumentList="string musicFileName">
      <![CDATA[native GetSoundFileDuration         takes string musicFileName returns integer]]>
    </Native>

    <Native Name="VolumeGroupSetVolume" ReturnType="nothing" ArgumentList="volumegroup vgroup, real scale">
      <![CDATA[native VolumeGroupSetVolume         takes volumegroup vgroup, real scale returns nothing]]>
    </Native>

    <Native Name="VolumeGroupReset" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native VolumeGroupReset             takes nothing returns nothing]]>
    </Native>

    <Native Name="GetSoundIsPlaying" ReturnType="boolean" ArgumentList="sound soundHandle">
      <![CDATA[native GetSoundIsPlaying            takes sound soundHandle returns boolean]]>
    </Native>

    <Native Name="GetSoundIsLoading" ReturnType="boolean" ArgumentList="sound soundHandle">
      <![CDATA[native GetSoundIsLoading            takes sound soundHandle returns boolean]]>
    </Native>

    <Native Name="RegisterStackedSound" ReturnType="nothing" ArgumentList="sound soundHandle, boolean byPosition, real rectwidth, real rectheight">
      <![CDATA[native RegisterStackedSound         takes sound soundHandle, boolean byPosition, real rectwidth, real rectheight returns nothing]]>
    </Native>

    <Native Name="UnregisterStackedSound" ReturnType="nothing" ArgumentList="sound soundHandle, boolean byPosition, real rectwidth, real rectheight">
      <![CDATA[native UnregisterStackedSound       takes sound soundHandle, boolean byPosition, real rectwidth, real rectheight returns nothing]]>
    </Native>

    <Native Name="AddWeatherEffect" ReturnType="weathereffect" ArgumentList="rect where, integer effectID">
      <![CDATA[native AddWeatherEffect             takes rect where, integer effectID returns weathereffect]]>
    </Native>

    <Native Name="RemoveWeatherEffect" ReturnType="nothing" ArgumentList="weathereffect whichEffect">
      <![CDATA[native RemoveWeatherEffect          takes weathereffect whichEffect returns nothing]]>
    </Native>

    <Native Name="EnableWeatherEffect" ReturnType="nothing" ArgumentList="weathereffect whichEffect, boolean enable">
      <![CDATA[native EnableWeatherEffect          takes weathereffect whichEffect, boolean enable returns nothing]]>
    </Native>

    <Native Name="TerrainDeformCrater" ReturnType="terraindeformation" ArgumentList="real x, real y, real radius, real depth, integer duration, boolean permanent">
      <![CDATA[native TerrainDeformCrater          takes real x, real y, real radius, real depth, integer duration, boolean permanent returns terraindeformation]]>
    </Native>

    <Native Name="TerrainDeformRipple" ReturnType="terraindeformation" ArgumentList="real x, real y, real radius, real depth, integer duration, integer count, real spaceWaves, real timeWaves, real radiusStartPct, boolean limitNeg">
      <![CDATA[native TerrainDeformRipple          takes real x, real y, real radius, real depth, integer duration, integer count, real spaceWaves, real timeWaves, real radiusStartPct, boolean limitNeg returns terraindeformation]]>
    </Native>

    <Native Name="TerrainDeformWave" ReturnType="terraindeformation" ArgumentList="real x, real y, real dirX, real dirY, real distance, real speed, real radius, real depth, integer trailTime, integer count">
      <![CDATA[native TerrainDeformWave            takes real x, real y, real dirX, real dirY, real distance, real speed, real radius, real depth, integer trailTime, integer count returns terraindeformation]]>
    </Native>

    <Native Name="TerrainDeformRandom" ReturnType="terraindeformation" ArgumentList="real x, real y, real radius, real minDelta, real maxDelta, integer duration, integer updateInterval">
      <![CDATA[native TerrainDeformRandom          takes real x, real y, real radius, real minDelta, real maxDelta, integer duration, integer updateInterval returns terraindeformation]]>
    </Native>

    <Native Name="TerrainDeformStop" ReturnType="nothing" ArgumentList="terraindeformation deformation, integer duration">
      <![CDATA[native TerrainDeformStop            takes terraindeformation deformation, integer duration returns nothing]]>
    </Native>

    <Native Name="TerrainDeformStopAll" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native TerrainDeformStopAll         takes nothing returns nothing]]>
    </Native>

    <Native Name="AddSpecialEffect" ReturnType="effect" ArgumentList="string modelName, real x, real y">
      <![CDATA[native AddSpecialEffect             takes string modelName, real x, real y returns effect]]>
    </Native>

    <Native Name="AddSpecialEffectLoc" ReturnType="effect" ArgumentList="string modelName, location where">
      <![CDATA[native AddSpecialEffectLoc          takes string modelName, location where returns effect]]>
    </Native>

    <Native Name="AddSpecialEffectTarget" ReturnType="effect" ArgumentList="string modelName, widget targetWidget, string attachPointName">
      <![CDATA[native AddSpecialEffectTarget       takes string modelName, widget targetWidget, string attachPointName returns effect]]>
    </Native>

    <Native Name="DestroyEffect" ReturnType="nothing" ArgumentList="effect whichEffect">
      <![CDATA[native DestroyEffect                takes effect whichEffect returns nothing]]>
    </Native>

    <Native Name="AddSpellEffect" ReturnType="effect" ArgumentList="string abilityString, effecttype t, real x, real y">
      <![CDATA[native AddSpellEffect               takes string abilityString, effecttype t, real x, real y returns effect]]>
    </Native>

    <Native Name="AddSpellEffectLoc" ReturnType="effect" ArgumentList="string abilityString, effecttype t,location where">
      <![CDATA[native AddSpellEffectLoc            takes string abilityString, effecttype t,location where returns effect]]>
    </Native>

    <Native Name="AddSpellEffectById" ReturnType="effect" ArgumentList="integer abilityId, effecttype t,real x, real y">
      <![CDATA[native AddSpellEffectById           takes integer abilityId, effecttype t,real x, real y returns effect]]>
    </Native>

    <Native Name="AddSpellEffectByIdLoc" ReturnType="effect" ArgumentList="integer abilityId, effecttype t,location where">
      <![CDATA[native AddSpellEffectByIdLoc        takes integer abilityId, effecttype t,location where returns effect]]>
    </Native>

    <Native Name="AddSpellEffectTarget" ReturnType="effect" ArgumentList="string modelName, effecttype t, widget targetWidget, string attachPoint">
      <![CDATA[native AddSpellEffectTarget         takes string modelName, effecttype t, widget targetWidget, string attachPoint returns effect]]>
    </Native>

    <Native Name="AddSpellEffectTargetById" ReturnType="effect" ArgumentList="integer abilityId, effecttype t, widget targetWidget, string attachPoint">
      <![CDATA[native AddSpellEffectTargetById     takes integer abilityId, effecttype t, widget targetWidget, string attachPoint returns effect]]>
    </Native>

    <Native Name="GetTerrainCliffLevel" ReturnType="integer" ArgumentList="real x, real y">
      <![CDATA[native GetTerrainCliffLevel         takes real x, real y returns integer]]>
    </Native>

    <Native Name="SetWaterBaseColor" ReturnType="nothing" ArgumentList="integer red, integer green, integer blue, integer alpha">
      <![CDATA[native SetWaterBaseColor            takes integer red, integer green, integer blue, integer alpha returns nothing]]>
    </Native>

    <Native Name="SetBlight" ReturnType="nothing" ArgumentList="player whichPlayer, real x, real y, real radius, boolean addBlight">
      <![CDATA[native SetBlight                takes player whichPlayer, real x, real y, real radius, boolean addBlight returns nothing]]>
    </Native>

    <Native Name="SetBlightRect" ReturnType="nothing" ArgumentList="player whichPlayer, rect r, boolean addBlight">
      <![CDATA[native SetBlightRect            takes player whichPlayer, rect r, boolean addBlight returns nothing]]>
    </Native>

    <Native Name="SetBlightPoint" ReturnType="nothing" ArgumentList="player whichPlayer, real x, real y, boolean addBlight">
      <![CDATA[native SetBlightPoint           takes player whichPlayer, real x, real y, boolean addBlight returns nothing]]>
    </Native>

    <Native Name="SetBlightLoc" ReturnType="nothing" ArgumentList="player whichPlayer, location whichLocation, real radius, boolean addBlight">
      <![CDATA[native SetBlightLoc             takes player whichPlayer, location whichLocation, real radius, boolean addBlight returns nothing]]>
    </Native>

    <Native Name="CreateBlightedGoldmine" ReturnType="unit" ArgumentList="player id, real x, real y, real face">
      <![CDATA[native CreateBlightedGoldmine   takes player id, real x, real y, real face returns unit]]>
    </Native>

    <Native Name="SetDoodadAnimation" ReturnType="nothing" ArgumentList="real x, real y, real radius, integer doodadID, boolean nearestOnly, string animName, boolean animRandom">
      <![CDATA[native SetDoodadAnimation       takes real x, real y, real radius, integer doodadID, boolean nearestOnly, string animName, boolean animRandom returns nothing]]>
    </Native>

    <Native Name="SetDoodadAnimationRect" ReturnType="nothing" ArgumentList="rect r, integer doodadID, string animName, boolean animRandom">
      <![CDATA[native SetDoodadAnimationRect   takes rect r, integer doodadID, string animName, boolean animRandom returns nothing]]>
    </Native>

    <Native Name="StartMeleeAI" ReturnType="nothing" ArgumentList="player num, string script">
      <![CDATA[native StartMeleeAI         takes player num, string script                 returns nothing]]>
    </Native>

    <Native Name="StartCampaignAI" ReturnType="nothing" ArgumentList="player num, string script">
      <![CDATA[native StartCampaignAI      takes player num, string script                 returns nothing]]>
    </Native>

    <Native Name="CommandAI" ReturnType="nothing" ArgumentList="player num, integer command, integer data">
      <![CDATA[native CommandAI            takes player num, integer command, integer data returns nothing]]>
    </Native>

    <Native Name="PauseCompAI" ReturnType="nothing" ArgumentList="player p,   boolean pause">
      <![CDATA[native PauseCompAI          takes player p,   boolean pause                 returns nothing]]>
    </Native>

    <Native Name="GetAIDifficulty" ReturnType="aidifficulty" ArgumentList="player num">
      <![CDATA[native GetAIDifficulty      takes player num                                returns aidifficulty]]>
    </Native>

    <Native Name="RemoveGuardPosition" ReturnType="nothing" ArgumentList="unit hUnit">
      <![CDATA[native RemoveGuardPosition  takes unit hUnit                                returns nothing]]>
    </Native>

    <Native Name="RecycleGuardPosition" ReturnType="nothing" ArgumentList="unit hUnit">
      <![CDATA[native RecycleGuardPosition takes unit hUnit                                returns nothing]]>
    </Native>

    <Native Name="RemoveAllGuardPositions" ReturnType="nothing" ArgumentList="player num">
      <![CDATA[native RemoveAllGuardPositions takes player num                             returns nothing]]>
    </Native>

    <Native Name="Cheat" ReturnType="nothing" ArgumentList="string cheatStr">
      <![CDATA[native Cheat            takes string cheatStr returns nothing]]>
    </Native>

    <Native Name="IsNoVictoryCheat" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[native IsNoVictoryCheat takes nothing returns boolean]]>
    </Native>

    <Native Name="IsNoDefeatCheat" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[native IsNoDefeatCheat  takes nothing returns boolean]]>
    </Native>

    <Native Name="Preload" ReturnType="nothing" ArgumentList="string filename">
      <![CDATA[native Preload          takes string filename returns nothing]]>
    </Native>

    <Native Name="PreloadEnd" ReturnType="nothing" ArgumentList="real timeout">
      <![CDATA[native PreloadEnd       takes real timeout returns nothing]]>
    </Native>

    <Native Name="PreloadStart" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native PreloadStart     takes nothing returns nothing]]>
    </Native>

    <Native Name="PreloadRefresh" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native PreloadRefresh   takes nothing returns nothing]]>
    </Native>

    <Native Name="PreloadEndEx" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native PreloadEndEx     takes nothing returns nothing]]>
    </Native>

    <Native Name="PreloadGenClear" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native PreloadGenClear  takes nothing returns nothing]]>
    </Native>

    <Native Name="PreloadGenStart" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[native PreloadGenStart  takes nothing returns nothing]]>
    </Native>

    <Native Name="PreloadGenEnd" ReturnType="nothing" ArgumentList="string filename">
      <![CDATA[native PreloadGenEnd    takes string filename returns nothing]]>
    </Native>

    <Native Name="Preloader" ReturnType="nothing" ArgumentList="string filename">
      <![CDATA[native Preloader        takes string filename returns nothing]]>
    </Native>

  </Natives>

  <BJs>

    <Variable Name="bj_PI" Type="real" Value="3.14159">
      <![CDATA[constant real      bj_PI                            = 3.14159]]>
    </Variable>

    <Variable Name="bj_E" Type="real" Value="2.71828">
      <![CDATA[constant real      bj_E                             = 2.71828]]>
    </Variable>

    <Variable Name="bj_CELLWIDTH" Type="real" Value="128.0">
      <![CDATA[constant real      bj_CELLWIDTH                     = 128.0]]>
    </Variable>

    <Variable Name="bj_CLIFFHEIGHT" Type="real" Value="128.0">
      <![CDATA[constant real      bj_CLIFFHEIGHT                   = 128.0]]>
    </Variable>

    <Variable Name="bj_UNIT_FACING" Type="real" Value="270.0">
      <![CDATA[constant real      bj_UNIT_FACING                   = 270.0]]>
    </Variable>

    <Variable Name="bj_RADTODEG" Type="real" Value="180.0/bj_PI">
      <![CDATA[constant real      bj_RADTODEG                      = 180.0/bj_PI]]>
    </Variable>

    <Variable Name="bj_DEGTORAD" Type="real" Value="bj_PI/180.0">
      <![CDATA[constant real      bj_DEGTORAD                      = bj_PI/180.0]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_QUEST" Type="real" Value="20.00">
      <![CDATA[constant real      bj_TEXT_DELAY_QUEST              = 20.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_QUESTUPDATE" Type="real" Value="20.00">
      <![CDATA[constant real      bj_TEXT_DELAY_QUESTUPDATE        = 20.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_QUESTDONE" Type="real" Value="20.00">
      <![CDATA[constant real      bj_TEXT_DELAY_QUESTDONE          = 20.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_QUESTFAILED" Type="real" Value="20.00">
      <![CDATA[constant real      bj_TEXT_DELAY_QUESTFAILED        = 20.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_QUESTREQUIREMENT" Type="real" Value="20.00">
      <![CDATA[constant real      bj_TEXT_DELAY_QUESTREQUIREMENT   = 20.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_MISSIONFAILED" Type="real" Value="20.00">
      <![CDATA[constant real      bj_TEXT_DELAY_MISSIONFAILED      = 20.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_ALWAYSHINT" Type="real" Value="12.00">
      <![CDATA[constant real      bj_TEXT_DELAY_ALWAYSHINT         = 12.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_HINT" Type="real" Value="12.00">
      <![CDATA[constant real      bj_TEXT_DELAY_HINT               = 12.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_SECRET" Type="real" Value="10.00">
      <![CDATA[constant real      bj_TEXT_DELAY_SECRET             = 10.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_UNITACQUIRED" Type="real" Value="15.00">
      <![CDATA[constant real      bj_TEXT_DELAY_UNITACQUIRED       = 15.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_UNITAVAILABLE" Type="real" Value="10.00">
      <![CDATA[constant real      bj_TEXT_DELAY_UNITAVAILABLE      = 10.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_ITEMACQUIRED" Type="real" Value="10.00">
      <![CDATA[constant real      bj_TEXT_DELAY_ITEMACQUIRED       = 10.00]]>
    </Variable>

    <Variable Name="bj_TEXT_DELAY_WARNING" Type="real" Value="12.00">
      <![CDATA[constant real      bj_TEXT_DELAY_WARNING            = 12.00]]>
    </Variable>

    <Variable Name="bj_QUEUE_DELAY_QUEST" Type="real" Value="5.00">
      <![CDATA[constant real      bj_QUEUE_DELAY_QUEST             =  5.00]]>
    </Variable>

    <Variable Name="bj_QUEUE_DELAY_HINT" Type="real" Value="5.00">
      <![CDATA[constant real      bj_QUEUE_DELAY_HINT              =  5.00]]>
    </Variable>

    <Variable Name="bj_QUEUE_DELAY_SECRET" Type="real" Value="3.00">
      <![CDATA[constant real      bj_QUEUE_DELAY_SECRET            =  3.00]]>
    </Variable>

    <Variable Name="bj_HANDICAP_EASY" Type="real" Value="60.00">
      <![CDATA[constant real      bj_HANDICAP_EASY                 = 60.00]]>
    </Variable>

    <Variable Name="bj_GAME_STARTED_THRESHOLD" Type="real" Value="0.01">
      <![CDATA[constant real      bj_GAME_STARTED_THRESHOLD        =  0.01]]>
    </Variable>

    <Variable Name="bj_WAIT_FOR_COND_MIN_INTERVAL" Type="real" Value="0.10">
      <![CDATA[constant real      bj_WAIT_FOR_COND_MIN_INTERVAL    =  0.10]]>
    </Variable>

    <Variable Name="bj_POLLED_WAIT_INTERVAL" Type="real" Value="0.10">
      <![CDATA[constant real      bj_POLLED_WAIT_INTERVAL          =  0.10]]>
    </Variable>

    <Variable Name="bj_POLLED_WAIT_SKIP_THRESHOLD" Type="real" Value="2.00">
      <![CDATA[constant real      bj_POLLED_WAIT_SKIP_THRESHOLD    =  2.00]]>
    </Variable>

    <Variable Name="bj_MAX_INVENTORY" Type="integer" Value="6">
      <![CDATA[constant integer   bj_MAX_INVENTORY                 =   6]]>
    </Variable>

    <Variable Name="bj_MAX_PLAYERS" Type="integer" Value="12">
      <![CDATA[constant integer   bj_MAX_PLAYERS                   =  12]]>
    </Variable>

    <Variable Name="bj_PLAYER_NEUTRAL_VICTIM" Type="integer" Value="13">
      <![CDATA[constant integer   bj_PLAYER_NEUTRAL_VICTIM         =  13]]>
    </Variable>

    <Variable Name="bj_PLAYER_NEUTRAL_EXTRA" Type="integer" Value="14">
      <![CDATA[constant integer   bj_PLAYER_NEUTRAL_EXTRA          =  14]]>
    </Variable>

    <Variable Name="bj_MAX_PLAYER_SLOTS" Type="integer" Value="16">
      <![CDATA[constant integer   bj_MAX_PLAYER_SLOTS              =  16]]>
    </Variable>

    <Variable Name="bj_MAX_SKELETONS" Type="integer" Value="25">
      <![CDATA[constant integer   bj_MAX_SKELETONS                 =  25]]>
    </Variable>

    <Variable Name="bj_MAX_STOCK_ITEM_SLOTS" Type="integer" Value="11">
      <![CDATA[constant integer   bj_MAX_STOCK_ITEM_SLOTS          =  11]]>
    </Variable>

    <Variable Name="bj_MAX_STOCK_UNIT_SLOTS" Type="integer" Value="11">
      <![CDATA[constant integer   bj_MAX_STOCK_UNIT_SLOTS          =  11]]>
    </Variable>

    <Variable Name="bj_MAX_ITEM_LEVEL" Type="integer" Value="10">
      <![CDATA[constant integer   bj_MAX_ITEM_LEVEL                =  10]]>
    </Variable>

    <Variable Name="bj_TOD_DAWN" Type="real" Value="6.00">
      <![CDATA[constant real      bj_TOD_DAWN                      = 6.00]]>
    </Variable>

    <Variable Name="bj_TOD_DUSK" Type="real" Value="18.00">
      <![CDATA[constant real      bj_TOD_DUSK                      = 18.00]]>
    </Variable>

    <Variable Name="bj_MELEE_STARTING_TOD" Type="real" Value="8.00">
      <![CDATA[constant real      bj_MELEE_STARTING_TOD            = 8.00]]>
    </Variable>

    <Variable Name="bj_MELEE_STARTING_GOLD_V0" Type="integer" Value="750">
      <![CDATA[constant integer   bj_MELEE_STARTING_GOLD_V0        = 750]]>
    </Variable>

    <Variable Name="bj_MELEE_STARTING_GOLD_V1" Type="integer" Value="500">
      <![CDATA[constant integer   bj_MELEE_STARTING_GOLD_V1        = 500]]>
    </Variable>

    <Variable Name="bj_MELEE_STARTING_LUMBER_V0" Type="integer" Value="200">
      <![CDATA[constant integer   bj_MELEE_STARTING_LUMBER_V0      = 200]]>
    </Variable>

    <Variable Name="bj_MELEE_STARTING_LUMBER_V1" Type="integer" Value="150">
      <![CDATA[constant integer   bj_MELEE_STARTING_LUMBER_V1      = 150]]>
    </Variable>

    <Variable Name="bj_MELEE_STARTING_HERO_TOKENS" Type="integer" Value="1">
      <![CDATA[constant integer   bj_MELEE_STARTING_HERO_TOKENS    = 1]]>
    </Variable>

    <Variable Name="bj_MELEE_HERO_LIMIT" Type="integer" Value="3">
      <![CDATA[constant integer   bj_MELEE_HERO_LIMIT              = 3]]>
    </Variable>

    <Variable Name="bj_MELEE_HERO_TYPE_LIMIT" Type="integer" Value="1">
      <![CDATA[constant integer   bj_MELEE_HERO_TYPE_LIMIT         = 1]]>
    </Variable>

    <Variable Name="bj_MELEE_MINE_SEARCH_RADIUS" Type="real" Value="2000">
      <![CDATA[constant real      bj_MELEE_MINE_SEARCH_RADIUS      = 2000]]>
    </Variable>

    <Variable Name="bj_MELEE_CLEAR_UNITS_RADIUS" Type="real" Value="1500">
      <![CDATA[constant real      bj_MELEE_CLEAR_UNITS_RADIUS      = 1500]]>
    </Variable>

    <Variable Name="bj_MELEE_CRIPPLE_TIMEOUT" Type="real" Value="120.00">
      <![CDATA[constant real      bj_MELEE_CRIPPLE_TIMEOUT         = 120.00]]>
    </Variable>

    <Variable Name="bj_MELEE_CRIPPLE_MSG_DURATION" Type="real" Value="20.00">
      <![CDATA[constant real      bj_MELEE_CRIPPLE_MSG_DURATION    = 20.00]]>
    </Variable>

    <Variable Name="bj_MELEE_MAX_TWINKED_HEROES_V0" Type="integer" Value="3">
      <![CDATA[constant integer   bj_MELEE_MAX_TWINKED_HEROES_V0   = 3]]>
    </Variable>

    <Variable Name="bj_MELEE_MAX_TWINKED_HEROES_V1" Type="integer" Value="1">
      <![CDATA[constant integer   bj_MELEE_MAX_TWINKED_HEROES_V1   = 1]]>
    </Variable>

    <Variable Name="bj_CREEP_ITEM_DELAY" Type="real" Value="0.50">
      <![CDATA[constant real      bj_CREEP_ITEM_DELAY              = 0.50]]>
    </Variable>

    <Variable Name="bj_STOCK_RESTOCK_INITIAL_DELAY" Type="real" Value="120">
      <![CDATA[constant real      bj_STOCK_RESTOCK_INITIAL_DELAY   = 120]]>
    </Variable>

    <Variable Name="bj_STOCK_RESTOCK_INTERVAL" Type="real" Value="30">
      <![CDATA[constant real      bj_STOCK_RESTOCK_INTERVAL        = 30]]>
    </Variable>

    <Variable Name="bj_STOCK_MAX_ITERATIONS" Type="integer" Value="20">
      <![CDATA[constant integer   bj_STOCK_MAX_ITERATIONS          = 20]]>
    </Variable>

    <Variable Name="bj_MAX_DEST_IN_REGION_EVENTS" Type="integer" Value="64">
      <![CDATA[constant integer   bj_MAX_DEST_IN_REGION_EVENTS     = 64]]>
    </Variable>

    <Variable Name="bj_CAMERA_MIN_FARZ" Type="integer" Value="100">
      <![CDATA[constant integer   bj_CAMERA_MIN_FARZ               = 100]]>
    </Variable>

    <Variable Name="bj_CAMERA_DEFAULT_DISTANCE" Type="integer" Value="1650">
      <![CDATA[constant integer   bj_CAMERA_DEFAULT_DISTANCE       = 1650]]>
    </Variable>

    <Variable Name="bj_CAMERA_DEFAULT_FARZ" Type="integer" Value="5000">
      <![CDATA[constant integer   bj_CAMERA_DEFAULT_FARZ           = 5000]]>
    </Variable>

    <Variable Name="bj_CAMERA_DEFAULT_AOA" Type="integer" Value="304">
      <![CDATA[constant integer   bj_CAMERA_DEFAULT_AOA            = 304]]>
    </Variable>

    <Variable Name="bj_CAMERA_DEFAULT_FOV" Type="integer" Value="70">
      <![CDATA[constant integer   bj_CAMERA_DEFAULT_FOV            = 70]]>
    </Variable>

    <Variable Name="bj_CAMERA_DEFAULT_ROLL" Type="integer" Value="0">
      <![CDATA[constant integer   bj_CAMERA_DEFAULT_ROLL           = 0]]>
    </Variable>

    <Variable Name="bj_CAMERA_DEFAULT_ROTATION" Type="integer" Value="90">
      <![CDATA[constant integer   bj_CAMERA_DEFAULT_ROTATION       = 90]]>
    </Variable>

    <Variable Name="bj_RESCUE_PING_TIME" Type="real" Value="2.00">
      <![CDATA[constant real      bj_RESCUE_PING_TIME              = 2.00]]>
    </Variable>

    <Variable Name="bj_NOTHING_SOUND_DURATION" Type="real" Value="5.00">
      <![CDATA[constant real      bj_NOTHING_SOUND_DURATION        = 5.00]]>
    </Variable>

    <Variable Name="bj_TRANSMISSION_PING_TIME" Type="real" Value="1.00">
      <![CDATA[constant real      bj_TRANSMISSION_PING_TIME        = 1.00]]>
    </Variable>

    <Variable Name="bj_TRANSMISSION_IND_RED" Type="integer" Value="255">
      <![CDATA[constant integer   bj_TRANSMISSION_IND_RED          = 255]]>
    </Variable>

    <Variable Name="bj_TRANSMISSION_IND_BLUE" Type="integer" Value="255">
      <![CDATA[constant integer   bj_TRANSMISSION_IND_BLUE         = 255]]>
    </Variable>

    <Variable Name="bj_TRANSMISSION_IND_GREEN" Type="integer" Value="255">
      <![CDATA[constant integer   bj_TRANSMISSION_IND_GREEN        = 255]]>
    </Variable>

    <Variable Name="bj_TRANSMISSION_IND_ALPHA" Type="integer" Value="255">
      <![CDATA[constant integer   bj_TRANSMISSION_IND_ALPHA        = 255]]>
    </Variable>

    <Variable Name="bj_TRANSMISSION_PORT_HANGTIME" Type="real" Value="1.50">
      <![CDATA[constant real      bj_TRANSMISSION_PORT_HANGTIME    = 1.50]]>
    </Variable>

    <Variable Name="bj_CINEMODE_INTERFACEFADE" Type="real" Value="0.50">
      <![CDATA[constant real      bj_CINEMODE_INTERFACEFADE        = 0.50]]>
    </Variable>

    <Variable Name="bj_CINEMODE_GAMESPEED" Type="gamespeed" Value="MAP_SPEED_NORMAL">
      <![CDATA[constant gamespeed bj_CINEMODE_GAMESPEED            = MAP_SPEED_NORMAL]]>
    </Variable>

    <Variable Name="bj_CINEMODE_VOLUME_UNITMOVEMENT" Type="real" Value="0.40">
      <![CDATA[constant real      bj_CINEMODE_VOLUME_UNITMOVEMENT  = 0.40]]>
    </Variable>

    <Variable Name="bj_CINEMODE_VOLUME_UNITSOUNDS" Type="real" Value="0.00">
      <![CDATA[constant real      bj_CINEMODE_VOLUME_UNITSOUNDS    = 0.00]]>
    </Variable>

    <Variable Name="bj_CINEMODE_VOLUME_COMBAT" Type="real" Value="0.40">
      <![CDATA[constant real      bj_CINEMODE_VOLUME_COMBAT        = 0.40]]>
    </Variable>

    <Variable Name="bj_CINEMODE_VOLUME_SPELLS" Type="real" Value="0.40">
      <![CDATA[constant real      bj_CINEMODE_VOLUME_SPELLS        = 0.40]]>
    </Variable>

    <Variable Name="bj_CINEMODE_VOLUME_UI" Type="real" Value="0.00">
      <![CDATA[constant real      bj_CINEMODE_VOLUME_UI            = 0.00]]>
    </Variable>

    <Variable Name="bj_CINEMODE_VOLUME_MUSIC" Type="real" Value="0.55">
      <![CDATA[constant real      bj_CINEMODE_VOLUME_MUSIC         = 0.55]]>
    </Variable>

    <Variable Name="bj_CINEMODE_VOLUME_AMBIENTSOUNDS" Type="real" Value="1.00">
      <![CDATA[constant real      bj_CINEMODE_VOLUME_AMBIENTSOUNDS = 1.00]]>
    </Variable>

    <Variable Name="bj_CINEMODE_VOLUME_FIRE" Type="real" Value="0.60">
      <![CDATA[constant real      bj_CINEMODE_VOLUME_FIRE          = 0.60]]>
    </Variable>

    <Variable Name="bj_SPEECH_VOLUME_UNITMOVEMENT" Type="real" Value="0.25">
      <![CDATA[constant real      bj_SPEECH_VOLUME_UNITMOVEMENT    = 0.25]]>
    </Variable>

    <Variable Name="bj_SPEECH_VOLUME_UNITSOUNDS" Type="real" Value="0.00">
      <![CDATA[constant real      bj_SPEECH_VOLUME_UNITSOUNDS      = 0.00]]>
    </Variable>

    <Variable Name="bj_SPEECH_VOLUME_COMBAT" Type="real" Value="0.25">
      <![CDATA[constant real      bj_SPEECH_VOLUME_COMBAT          = 0.25]]>
    </Variable>

    <Variable Name="bj_SPEECH_VOLUME_SPELLS" Type="real" Value="0.25">
      <![CDATA[constant real      bj_SPEECH_VOLUME_SPELLS          = 0.25]]>
    </Variable>

    <Variable Name="bj_SPEECH_VOLUME_UI" Type="real" Value="0.00">
      <![CDATA[constant real      bj_SPEECH_VOLUME_UI              = 0.00]]>
    </Variable>

    <Variable Name="bj_SPEECH_VOLUME_MUSIC" Type="real" Value="0.55">
      <![CDATA[constant real      bj_SPEECH_VOLUME_MUSIC           = 0.55]]>
    </Variable>

    <Variable Name="bj_SPEECH_VOLUME_AMBIENTSOUNDS" Type="real" Value="1.00">
      <![CDATA[constant real      bj_SPEECH_VOLUME_AMBIENTSOUNDS   = 1.00]]>
    </Variable>

    <Variable Name="bj_SPEECH_VOLUME_FIRE" Type="real" Value="0.60">
      <![CDATA[constant real      bj_SPEECH_VOLUME_FIRE            = 0.60]]>
    </Variable>

    <Variable Name="bj_SMARTPAN_TRESHOLD_PAN" Type="real" Value="500">
      <![CDATA[constant real      bj_SMARTPAN_TRESHOLD_PAN         = 500]]>
    </Variable>

    <Variable Name="bj_SMARTPAN_TRESHOLD_SNAP" Type="real" Value="3500">
      <![CDATA[constant real      bj_SMARTPAN_TRESHOLD_SNAP        = 3500]]>
    </Variable>

    <Variable Name="bj_MAX_QUEUED_TRIGGERS" Type="integer" Value="100">
      <![CDATA[constant integer   bj_MAX_QUEUED_TRIGGERS           = 100]]>
    </Variable>

    <Variable Name="bj_QUEUED_TRIGGER_TIMEOUT" Type="real" Value="180.00">
      <![CDATA[constant real      bj_QUEUED_TRIGGER_TIMEOUT        = 180.00]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_T" Type="integer" Value="0">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_T        = 0]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_H" Type="integer" Value="1">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_H        = 1]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_U" Type="integer" Value="2">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_U        = 2]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_O" Type="integer" Value="3">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_O        = 3]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_N" Type="integer" Value="4">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_N        = 4]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_XN" Type="integer" Value="5">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_XN       = 5]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_XH" Type="integer" Value="6">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_XH       = 6]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_XU" Type="integer" Value="7">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_XU       = 7]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_INDEX_XO" Type="integer" Value="8">
      <![CDATA[constant integer   bj_CAMPAIGN_INDEX_XO       = 8]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_T" Type="integer" Value="0">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_T       = 0]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_H" Type="integer" Value="1">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_H       = 1]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_U" Type="integer" Value="2">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_U       = 2]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_O" Type="integer" Value="3">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_O       = 3]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_N" Type="integer" Value="4">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_N       = 4]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_XN" Type="integer" Value="0">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_XN      = 0]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_XH" Type="integer" Value="1">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_XH      = 1]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_XU" Type="integer" Value="2">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_XU      = 2]]>
    </Variable>

    <Variable Name="bj_CAMPAIGN_OFFSET_XO" Type="integer" Value="3">
      <![CDATA[constant integer   bj_CAMPAIGN_OFFSET_XO      = 3]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_T00" Type="integer" Value="bj_CAMPAIGN_OFFSET_T * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_T00       = bj_CAMPAIGN_OFFSET_T * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_T01" Type="integer" Value="bj_CAMPAIGN_OFFSET_T * 1000 + 1">
      <![CDATA[constant integer   bj_MISSION_INDEX_T01       = bj_CAMPAIGN_OFFSET_T * 1000 + 1]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H00" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_H00       = bj_CAMPAIGN_OFFSET_H * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H01" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 1">
      <![CDATA[constant integer   bj_MISSION_INDEX_H01       = bj_CAMPAIGN_OFFSET_H * 1000 + 1]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H02" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 2">
      <![CDATA[constant integer   bj_MISSION_INDEX_H02       = bj_CAMPAIGN_OFFSET_H * 1000 + 2]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H03" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 3">
      <![CDATA[constant integer   bj_MISSION_INDEX_H03       = bj_CAMPAIGN_OFFSET_H * 1000 + 3]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H04" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 4">
      <![CDATA[constant integer   bj_MISSION_INDEX_H04       = bj_CAMPAIGN_OFFSET_H * 1000 + 4]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H05" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 5">
      <![CDATA[constant integer   bj_MISSION_INDEX_H05       = bj_CAMPAIGN_OFFSET_H * 1000 + 5]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H06" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 6">
      <![CDATA[constant integer   bj_MISSION_INDEX_H06       = bj_CAMPAIGN_OFFSET_H * 1000 + 6]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H07" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 7">
      <![CDATA[constant integer   bj_MISSION_INDEX_H07       = bj_CAMPAIGN_OFFSET_H * 1000 + 7]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H08" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 8">
      <![CDATA[constant integer   bj_MISSION_INDEX_H08       = bj_CAMPAIGN_OFFSET_H * 1000 + 8]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H09" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 9">
      <![CDATA[constant integer   bj_MISSION_INDEX_H09       = bj_CAMPAIGN_OFFSET_H * 1000 + 9]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H10" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 10">
      <![CDATA[constant integer   bj_MISSION_INDEX_H10       = bj_CAMPAIGN_OFFSET_H * 1000 + 10]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_H11" Type="integer" Value="bj_CAMPAIGN_OFFSET_H * 1000 + 11">
      <![CDATA[constant integer   bj_MISSION_INDEX_H11       = bj_CAMPAIGN_OFFSET_H * 1000 + 11]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U00" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_U00       = bj_CAMPAIGN_OFFSET_U * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U01" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 1">
      <![CDATA[constant integer   bj_MISSION_INDEX_U01       = bj_CAMPAIGN_OFFSET_U * 1000 + 1]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U02" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 2">
      <![CDATA[constant integer   bj_MISSION_INDEX_U02       = bj_CAMPAIGN_OFFSET_U * 1000 + 2]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U03" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 3">
      <![CDATA[constant integer   bj_MISSION_INDEX_U03       = bj_CAMPAIGN_OFFSET_U * 1000 + 3]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U05" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 4">
      <![CDATA[constant integer   bj_MISSION_INDEX_U05       = bj_CAMPAIGN_OFFSET_U * 1000 + 4]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U07" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 5">
      <![CDATA[constant integer   bj_MISSION_INDEX_U07       = bj_CAMPAIGN_OFFSET_U * 1000 + 5]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U08" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 6">
      <![CDATA[constant integer   bj_MISSION_INDEX_U08       = bj_CAMPAIGN_OFFSET_U * 1000 + 6]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U09" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 7">
      <![CDATA[constant integer   bj_MISSION_INDEX_U09       = bj_CAMPAIGN_OFFSET_U * 1000 + 7]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U10" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 8">
      <![CDATA[constant integer   bj_MISSION_INDEX_U10       = bj_CAMPAIGN_OFFSET_U * 1000 + 8]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_U11" Type="integer" Value="bj_CAMPAIGN_OFFSET_U * 1000 + 9">
      <![CDATA[constant integer   bj_MISSION_INDEX_U11       = bj_CAMPAIGN_OFFSET_U * 1000 + 9]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O00" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_O00       = bj_CAMPAIGN_OFFSET_O * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O01" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 1">
      <![CDATA[constant integer   bj_MISSION_INDEX_O01       = bj_CAMPAIGN_OFFSET_O * 1000 + 1]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O02" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 2">
      <![CDATA[constant integer   bj_MISSION_INDEX_O02       = bj_CAMPAIGN_OFFSET_O * 1000 + 2]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O03" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 3">
      <![CDATA[constant integer   bj_MISSION_INDEX_O03       = bj_CAMPAIGN_OFFSET_O * 1000 + 3]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O04" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 4">
      <![CDATA[constant integer   bj_MISSION_INDEX_O04       = bj_CAMPAIGN_OFFSET_O * 1000 + 4]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O05" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 5">
      <![CDATA[constant integer   bj_MISSION_INDEX_O05       = bj_CAMPAIGN_OFFSET_O * 1000 + 5]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O06" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 6">
      <![CDATA[constant integer   bj_MISSION_INDEX_O06       = bj_CAMPAIGN_OFFSET_O * 1000 + 6]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O07" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 7">
      <![CDATA[constant integer   bj_MISSION_INDEX_O07       = bj_CAMPAIGN_OFFSET_O * 1000 + 7]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O08" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 8">
      <![CDATA[constant integer   bj_MISSION_INDEX_O08       = bj_CAMPAIGN_OFFSET_O * 1000 + 8]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O09" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 9">
      <![CDATA[constant integer   bj_MISSION_INDEX_O09       = bj_CAMPAIGN_OFFSET_O * 1000 + 9]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_O10" Type="integer" Value="bj_CAMPAIGN_OFFSET_O * 1000 + 10">
      <![CDATA[constant integer   bj_MISSION_INDEX_O10       = bj_CAMPAIGN_OFFSET_O * 1000 + 10]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N00" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_N00       = bj_CAMPAIGN_OFFSET_N * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N01" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 1">
      <![CDATA[constant integer   bj_MISSION_INDEX_N01       = bj_CAMPAIGN_OFFSET_N * 1000 + 1]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N02" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 2">
      <![CDATA[constant integer   bj_MISSION_INDEX_N02       = bj_CAMPAIGN_OFFSET_N * 1000 + 2]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N03" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 3">
      <![CDATA[constant integer   bj_MISSION_INDEX_N03       = bj_CAMPAIGN_OFFSET_N * 1000 + 3]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N04" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 4">
      <![CDATA[constant integer   bj_MISSION_INDEX_N04       = bj_CAMPAIGN_OFFSET_N * 1000 + 4]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N05" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 5">
      <![CDATA[constant integer   bj_MISSION_INDEX_N05       = bj_CAMPAIGN_OFFSET_N * 1000 + 5]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N06" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 6">
      <![CDATA[constant integer   bj_MISSION_INDEX_N06       = bj_CAMPAIGN_OFFSET_N * 1000 + 6]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N07" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 7">
      <![CDATA[constant integer   bj_MISSION_INDEX_N07       = bj_CAMPAIGN_OFFSET_N * 1000 + 7]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N08" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 8">
      <![CDATA[constant integer   bj_MISSION_INDEX_N08       = bj_CAMPAIGN_OFFSET_N * 1000 + 8]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_N09" Type="integer" Value="bj_CAMPAIGN_OFFSET_N * 1000 + 9">
      <![CDATA[constant integer   bj_MISSION_INDEX_N09       = bj_CAMPAIGN_OFFSET_N * 1000 + 9]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN00" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN00       = bj_CAMPAIGN_OFFSET_XN * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN01" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 1">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN01       = bj_CAMPAIGN_OFFSET_XN * 1000 + 1]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN02" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 2">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN02       = bj_CAMPAIGN_OFFSET_XN * 1000 + 2]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN03" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 3">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN03       = bj_CAMPAIGN_OFFSET_XN * 1000 + 3]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN04" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 4">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN04       = bj_CAMPAIGN_OFFSET_XN * 1000 + 4]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN05" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 5">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN05       = bj_CAMPAIGN_OFFSET_XN * 1000 + 5]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN06" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 6">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN06       = bj_CAMPAIGN_OFFSET_XN * 1000 + 6]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN07" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 7">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN07       = bj_CAMPAIGN_OFFSET_XN * 1000 + 7]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN08" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 8">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN08       = bj_CAMPAIGN_OFFSET_XN * 1000 + 8]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN09" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 9">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN09       = bj_CAMPAIGN_OFFSET_XN * 1000 + 9]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XN10" Type="integer" Value="bj_CAMPAIGN_OFFSET_XN * 1000 + 10">
      <![CDATA[constant integer   bj_MISSION_INDEX_XN10       = bj_CAMPAIGN_OFFSET_XN * 1000 + 10]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH00" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH00       = bj_CAMPAIGN_OFFSET_XH * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH01" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 1">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH01       = bj_CAMPAIGN_OFFSET_XH * 1000 + 1]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH02" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 2">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH02       = bj_CAMPAIGN_OFFSET_XH * 1000 + 2]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH03" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 3">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH03       = bj_CAMPAIGN_OFFSET_XH * 1000 + 3]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH04" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 4">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH04       = bj_CAMPAIGN_OFFSET_XH * 1000 + 4]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH05" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 5">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH05       = bj_CAMPAIGN_OFFSET_XH * 1000 + 5]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH06" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 6">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH06       = bj_CAMPAIGN_OFFSET_XH * 1000 + 6]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH07" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 7">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH07       = bj_CAMPAIGN_OFFSET_XH * 1000 + 7]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH08" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 8">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH08       = bj_CAMPAIGN_OFFSET_XH * 1000 + 8]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XH09" Type="integer" Value="bj_CAMPAIGN_OFFSET_XH * 1000 + 9">
      <![CDATA[constant integer   bj_MISSION_INDEX_XH09       = bj_CAMPAIGN_OFFSET_XH * 1000 + 9]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU00" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU00       = bj_CAMPAIGN_OFFSET_XU * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU01" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 1">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU01       = bj_CAMPAIGN_OFFSET_XU * 1000 + 1]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU02" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 2">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU02       = bj_CAMPAIGN_OFFSET_XU * 1000 + 2]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU03" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 3">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU03       = bj_CAMPAIGN_OFFSET_XU * 1000 + 3]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU04" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 4">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU04       = bj_CAMPAIGN_OFFSET_XU * 1000 + 4]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU05" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 5">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU05       = bj_CAMPAIGN_OFFSET_XU * 1000 + 5]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU06" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 6">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU06       = bj_CAMPAIGN_OFFSET_XU * 1000 + 6]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU07" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 7">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU07       = bj_CAMPAIGN_OFFSET_XU * 1000 + 7]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU08" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 8">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU08       = bj_CAMPAIGN_OFFSET_XU * 1000 + 8]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU09" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 9">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU09       = bj_CAMPAIGN_OFFSET_XU * 1000 + 9]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU10" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 10">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU10       = bj_CAMPAIGN_OFFSET_XU * 1000 + 10]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU11" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 11">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU11       = bj_CAMPAIGN_OFFSET_XU * 1000 + 11]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU12" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 12">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU12       = bj_CAMPAIGN_OFFSET_XU * 1000 + 12]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XU13" Type="integer" Value="bj_CAMPAIGN_OFFSET_XU * 1000 + 13">
      <![CDATA[constant integer   bj_MISSION_INDEX_XU13       = bj_CAMPAIGN_OFFSET_XU * 1000 + 13]]>
    </Variable>

    <Variable Name="bj_MISSION_INDEX_XO00" Type="integer" Value="bj_CAMPAIGN_OFFSET_XO * 1000 + 0">
      <![CDATA[constant integer   bj_MISSION_INDEX_XO00       = bj_CAMPAIGN_OFFSET_XO * 1000 + 0]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_TOP" Type="integer" Value="0">
      <![CDATA[constant integer   bj_CINEMATICINDEX_TOP      = 0]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_HOP" Type="integer" Value="1">
      <![CDATA[constant integer   bj_CINEMATICINDEX_HOP      = 1]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_HED" Type="integer" Value="2">
      <![CDATA[constant integer   bj_CINEMATICINDEX_HED      = 2]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_OOP" Type="integer" Value="3">
      <![CDATA[constant integer   bj_CINEMATICINDEX_OOP      = 3]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_OED" Type="integer" Value="4">
      <![CDATA[constant integer   bj_CINEMATICINDEX_OED      = 4]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_UOP" Type="integer" Value="5">
      <![CDATA[constant integer   bj_CINEMATICINDEX_UOP      = 5]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_UED" Type="integer" Value="6">
      <![CDATA[constant integer   bj_CINEMATICINDEX_UED      = 6]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_NOP" Type="integer" Value="7">
      <![CDATA[constant integer   bj_CINEMATICINDEX_NOP      = 7]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_NED" Type="integer" Value="8">
      <![CDATA[constant integer   bj_CINEMATICINDEX_NED      = 8]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_XOP" Type="integer" Value="9">
      <![CDATA[constant integer   bj_CINEMATICINDEX_XOP      = 9]]>
    </Variable>

    <Variable Name="bj_CINEMATICINDEX_XED" Type="integer" Value="10">
      <![CDATA[constant integer   bj_CINEMATICINDEX_XED      = 10]]>
    </Variable>

    <Variable Name="bj_ALLIANCE_UNALLIED" Type="integer" Value="0">
      <![CDATA[constant integer   bj_ALLIANCE_UNALLIED        = 0]]>
    </Variable>

    <Variable Name="bj_ALLIANCE_UNALLIED_VISION" Type="integer" Value="1">
      <![CDATA[constant integer   bj_ALLIANCE_UNALLIED_VISION = 1]]>
    </Variable>

    <Variable Name="bj_ALLIANCE_ALLIED" Type="integer" Value="2">
      <![CDATA[constant integer   bj_ALLIANCE_ALLIED          = 2]]>
    </Variable>

    <Variable Name="bj_ALLIANCE_ALLIED_VISION" Type="integer" Value="3">
      <![CDATA[constant integer   bj_ALLIANCE_ALLIED_VISION   = 3]]>
    </Variable>

    <Variable Name="bj_ALLIANCE_ALLIED_UNITS" Type="integer" Value="4">
      <![CDATA[constant integer   bj_ALLIANCE_ALLIED_UNITS    = 4]]>
    </Variable>

    <Variable Name="bj_ALLIANCE_ALLIED_ADVUNITS" Type="integer" Value="5">
      <![CDATA[constant integer   bj_ALLIANCE_ALLIED_ADVUNITS = 5]]>
    </Variable>

    <Variable Name="bj_ALLIANCE_NEUTRAL" Type="integer" Value="6">
      <![CDATA[constant integer   bj_ALLIANCE_NEUTRAL         = 6]]>
    </Variable>

    <Variable Name="bj_ALLIANCE_NEUTRAL_VISION" Type="integer" Value="7">
      <![CDATA[constant integer   bj_ALLIANCE_NEUTRAL_VISION  = 7]]>
    </Variable>

    <Variable Name="bj_KEYEVENTTYPE_DEPRESS" Type="integer" Value="0">
      <![CDATA[constant integer   bj_KEYEVENTTYPE_DEPRESS     = 0]]>
    </Variable>

    <Variable Name="bj_KEYEVENTTYPE_RELEASE" Type="integer" Value="1">
      <![CDATA[constant integer   bj_KEYEVENTTYPE_RELEASE     = 1]]>
    </Variable>

    <Variable Name="bj_KEYEVENTKEY_LEFT" Type="integer" Value="0">
      <![CDATA[constant integer   bj_KEYEVENTKEY_LEFT         = 0]]>
    </Variable>

    <Variable Name="bj_KEYEVENTKEY_RIGHT" Type="integer" Value="1">
      <![CDATA[constant integer   bj_KEYEVENTKEY_RIGHT        = 1]]>
    </Variable>

    <Variable Name="bj_KEYEVENTKEY_DOWN" Type="integer" Value="2">
      <![CDATA[constant integer   bj_KEYEVENTKEY_DOWN         = 2]]>
    </Variable>

    <Variable Name="bj_KEYEVENTKEY_UP" Type="integer" Value="3">
      <![CDATA[constant integer   bj_KEYEVENTKEY_UP           = 3]]>
    </Variable>

    <Variable Name="bj_TIMETYPE_ADD" Type="integer" Value="0">
      <![CDATA[constant integer   bj_TIMETYPE_ADD             = 0]]>
    </Variable>

    <Variable Name="bj_TIMETYPE_SET" Type="integer" Value="1">
      <![CDATA[constant integer   bj_TIMETYPE_SET             = 1]]>
    </Variable>

    <Variable Name="bj_TIMETYPE_SUB" Type="integer" Value="2">
      <![CDATA[constant integer   bj_TIMETYPE_SUB             = 2]]>
    </Variable>

    <Variable Name="bj_CAMERABOUNDS_ADJUST_ADD" Type="integer" Value="0">
      <![CDATA[constant integer   bj_CAMERABOUNDS_ADJUST_ADD  = 0]]>
    </Variable>

    <Variable Name="bj_CAMERABOUNDS_ADJUST_SUB" Type="integer" Value="1">
      <![CDATA[constant integer   bj_CAMERABOUNDS_ADJUST_SUB  = 1]]>
    </Variable>

    <Variable Name="bj_QUESTTYPE_REQ_DISCOVERED" Type="integer" Value="0">
      <![CDATA[constant integer   bj_QUESTTYPE_REQ_DISCOVERED   = 0]]>
    </Variable>

    <Variable Name="bj_QUESTTYPE_REQ_UNDISCOVERED" Type="integer" Value="1">
      <![CDATA[constant integer   bj_QUESTTYPE_REQ_UNDISCOVERED = 1]]>
    </Variable>

    <Variable Name="bj_QUESTTYPE_OPT_DISCOVERED" Type="integer" Value="2">
      <![CDATA[constant integer   bj_QUESTTYPE_OPT_DISCOVERED   = 2]]>
    </Variable>

    <Variable Name="bj_QUESTTYPE_OPT_UNDISCOVERED" Type="integer" Value="3">
      <![CDATA[constant integer   bj_QUESTTYPE_OPT_UNDISCOVERED = 3]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_DISCOVERED" Type="integer" Value="0">
      <![CDATA[constant integer   bj_QUESTMESSAGE_DISCOVERED    = 0]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_UPDATED" Type="integer" Value="1">
      <![CDATA[constant integer   bj_QUESTMESSAGE_UPDATED       = 1]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_COMPLETED" Type="integer" Value="2">
      <![CDATA[constant integer   bj_QUESTMESSAGE_COMPLETED     = 2]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_FAILED" Type="integer" Value="3">
      <![CDATA[constant integer   bj_QUESTMESSAGE_FAILED        = 3]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_REQUIREMENT" Type="integer" Value="4">
      <![CDATA[constant integer   bj_QUESTMESSAGE_REQUIREMENT   = 4]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_MISSIONFAILED" Type="integer" Value="5">
      <![CDATA[constant integer   bj_QUESTMESSAGE_MISSIONFAILED = 5]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_ALWAYSHINT" Type="integer" Value="6">
      <![CDATA[constant integer   bj_QUESTMESSAGE_ALWAYSHINT    = 6]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_HINT" Type="integer" Value="7">
      <![CDATA[constant integer   bj_QUESTMESSAGE_HINT          = 7]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_SECRET" Type="integer" Value="8">
      <![CDATA[constant integer   bj_QUESTMESSAGE_SECRET        = 8]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_UNITACQUIRED" Type="integer" Value="9">
      <![CDATA[constant integer   bj_QUESTMESSAGE_UNITACQUIRED  = 9]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_UNITAVAILABLE" Type="integer" Value="10">
      <![CDATA[constant integer   bj_QUESTMESSAGE_UNITAVAILABLE = 10]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_ITEMACQUIRED" Type="integer" Value="11">
      <![CDATA[constant integer   bj_QUESTMESSAGE_ITEMACQUIRED  = 11]]>
    </Variable>

    <Variable Name="bj_QUESTMESSAGE_WARNING" Type="integer" Value="12">
      <![CDATA[constant integer   bj_QUESTMESSAGE_WARNING       = 12]]>
    </Variable>

    <Variable Name="bj_SORTTYPE_SORTBYVALUE" Type="integer" Value="0">
      <![CDATA[constant integer   bj_SORTTYPE_SORTBYVALUE     = 0]]>
    </Variable>

    <Variable Name="bj_SORTTYPE_SORTBYPLAYER" Type="integer" Value="1">
      <![CDATA[constant integer   bj_SORTTYPE_SORTBYPLAYER    = 1]]>
    </Variable>

    <Variable Name="bj_SORTTYPE_SORTBYLABEL" Type="integer" Value="2">
      <![CDATA[constant integer   bj_SORTTYPE_SORTBYLABEL     = 2]]>
    </Variable>

    <Variable Name="bj_CINEFADETYPE_FADEIN" Type="integer" Value="0">
      <![CDATA[constant integer   bj_CINEFADETYPE_FADEIN      = 0]]>
    </Variable>

    <Variable Name="bj_CINEFADETYPE_FADEOUT" Type="integer" Value="1">
      <![CDATA[constant integer   bj_CINEFADETYPE_FADEOUT     = 1]]>
    </Variable>

    <Variable Name="bj_CINEFADETYPE_FADEOUTIN" Type="integer" Value="2">
      <![CDATA[constant integer   bj_CINEFADETYPE_FADEOUTIN   = 2]]>
    </Variable>

    <Variable Name="bj_REMOVEBUFFS_POSITIVE" Type="integer" Value="0">
      <![CDATA[constant integer   bj_REMOVEBUFFS_POSITIVE     = 0]]>
    </Variable>

    <Variable Name="bj_REMOVEBUFFS_NEGATIVE" Type="integer" Value="1">
      <![CDATA[constant integer   bj_REMOVEBUFFS_NEGATIVE     = 1]]>
    </Variable>

    <Variable Name="bj_REMOVEBUFFS_ALL" Type="integer" Value="2">
      <![CDATA[constant integer   bj_REMOVEBUFFS_ALL          = 2]]>
    </Variable>

    <Variable Name="bj_REMOVEBUFFS_NONTLIFE" Type="integer" Value="3">
      <![CDATA[constant integer   bj_REMOVEBUFFS_NONTLIFE     = 3]]>
    </Variable>

    <Variable Name="bj_BUFF_POLARITY_POSITIVE" Type="integer" Value="0">
      <![CDATA[constant integer   bj_BUFF_POLARITY_POSITIVE   = 0]]>
    </Variable>

    <Variable Name="bj_BUFF_POLARITY_NEGATIVE" Type="integer" Value="1">
      <![CDATA[constant integer   bj_BUFF_POLARITY_NEGATIVE   = 1]]>
    </Variable>

    <Variable Name="bj_BUFF_POLARITY_EITHER" Type="integer" Value="2">
      <![CDATA[constant integer   bj_BUFF_POLARITY_EITHER     = 2]]>
    </Variable>

    <Variable Name="bj_BUFF_RESIST_MAGIC" Type="integer" Value="0">
      <![CDATA[constant integer   bj_BUFF_RESIST_MAGIC        = 0]]>
    </Variable>

    <Variable Name="bj_BUFF_RESIST_PHYSICAL" Type="integer" Value="1">
      <![CDATA[constant integer   bj_BUFF_RESIST_PHYSICAL     = 1]]>
    </Variable>

    <Variable Name="bj_BUFF_RESIST_EITHER" Type="integer" Value="2">
      <![CDATA[constant integer   bj_BUFF_RESIST_EITHER       = 2]]>
    </Variable>

    <Variable Name="bj_BUFF_RESIST_BOTH" Type="integer" Value="3">
      <![CDATA[constant integer   bj_BUFF_RESIST_BOTH         = 3]]>
    </Variable>

    <Variable Name="bj_HEROSTAT_STR" Type="integer" Value="0">
      <![CDATA[constant integer   bj_HEROSTAT_STR             = 0]]>
    </Variable>

    <Variable Name="bj_HEROSTAT_AGI" Type="integer" Value="1">
      <![CDATA[constant integer   bj_HEROSTAT_AGI             = 1]]>
    </Variable>

    <Variable Name="bj_HEROSTAT_INT" Type="integer" Value="2">
      <![CDATA[constant integer   bj_HEROSTAT_INT             = 2]]>
    </Variable>

    <Variable Name="bj_MODIFYMETHOD_ADD" Type="integer" Value="0">
      <![CDATA[constant integer   bj_MODIFYMETHOD_ADD    = 0]]>
    </Variable>

    <Variable Name="bj_MODIFYMETHOD_SUB" Type="integer" Value="1">
      <![CDATA[constant integer   bj_MODIFYMETHOD_SUB    = 1]]>
    </Variable>

    <Variable Name="bj_MODIFYMETHOD_SET" Type="integer" Value="2">
      <![CDATA[constant integer   bj_MODIFYMETHOD_SET    = 2]]>
    </Variable>

    <Variable Name="bj_UNIT_STATE_METHOD_ABSOLUTE" Type="integer" Value="0">
      <![CDATA[constant integer   bj_UNIT_STATE_METHOD_ABSOLUTE = 0]]>
    </Variable>

    <Variable Name="bj_UNIT_STATE_METHOD_RELATIVE" Type="integer" Value="1">
      <![CDATA[constant integer   bj_UNIT_STATE_METHOD_RELATIVE = 1]]>
    </Variable>

    <Variable Name="bj_UNIT_STATE_METHOD_DEFAULTS" Type="integer" Value="2">
      <![CDATA[constant integer   bj_UNIT_STATE_METHOD_DEFAULTS = 2]]>
    </Variable>

    <Variable Name="bj_UNIT_STATE_METHOD_MAXIMUM" Type="integer" Value="3">
      <![CDATA[constant integer   bj_UNIT_STATE_METHOD_MAXIMUM  = 3]]>
    </Variable>

    <Variable Name="bj_GATEOPERATION_CLOSE" Type="integer" Value="0">
      <![CDATA[constant integer   bj_GATEOPERATION_CLOSE      = 0]]>
    </Variable>

    <Variable Name="bj_GATEOPERATION_OPEN" Type="integer" Value="1">
      <![CDATA[constant integer   bj_GATEOPERATION_OPEN       = 1]]>
    </Variable>

    <Variable Name="bj_GATEOPERATION_DESTROY" Type="integer" Value="2">
      <![CDATA[constant integer   bj_GATEOPERATION_DESTROY    = 2]]>
    </Variable>

    <Variable Name="bj_GAMECACHE_BOOLEAN" Type="integer" Value="0">
      <![CDATA[constant integer   bj_GAMECACHE_BOOLEAN        = 0]]>
    </Variable>

    <Variable Name="bj_GAMECACHE_INTEGER" Type="integer" Value="1">
      <![CDATA[constant integer   bj_GAMECACHE_INTEGER        = 1]]>
    </Variable>

    <Variable Name="bj_GAMECACHE_REAL" Type="integer" Value="2">
      <![CDATA[constant integer   bj_GAMECACHE_REAL           = 2]]>
    </Variable>

    <Variable Name="bj_GAMECACHE_UNIT" Type="integer" Value="3">
      <![CDATA[constant integer   bj_GAMECACHE_UNIT           = 3]]>
    </Variable>

    <Variable Name="bj_GAMECACHE_STRING" Type="integer" Value="4">
      <![CDATA[constant integer   bj_GAMECACHE_STRING         = 4]]>
    </Variable>

    <Variable Name="bj_ITEM_STATUS_HIDDEN" Type="integer" Value="0">
      <![CDATA[constant integer   bj_ITEM_STATUS_HIDDEN       = 0]]>
    </Variable>

    <Variable Name="bj_ITEM_STATUS_OWNED" Type="integer" Value="1">
      <![CDATA[constant integer   bj_ITEM_STATUS_OWNED        = 1]]>
    </Variable>

    <Variable Name="bj_ITEM_STATUS_INVULNERABLE" Type="integer" Value="2">
      <![CDATA[constant integer   bj_ITEM_STATUS_INVULNERABLE = 2]]>
    </Variable>

    <Variable Name="bj_ITEM_STATUS_POWERUP" Type="integer" Value="3">
      <![CDATA[constant integer   bj_ITEM_STATUS_POWERUP      = 3]]>
    </Variable>

    <Variable Name="bj_ITEM_STATUS_SELLABLE" Type="integer" Value="4">
      <![CDATA[constant integer   bj_ITEM_STATUS_SELLABLE     = 4]]>
    </Variable>

    <Variable Name="bj_ITEM_STATUS_PAWNABLE" Type="integer" Value="5">
      <![CDATA[constant integer   bj_ITEM_STATUS_PAWNABLE     = 5]]>
    </Variable>

    <Variable Name="bj_ITEMCODE_STATUS_POWERUP" Type="integer" Value="0">
      <![CDATA[constant integer   bj_ITEMCODE_STATUS_POWERUP  = 0]]>
    </Variable>

    <Variable Name="bj_ITEMCODE_STATUS_SELLABLE" Type="integer" Value="1">
      <![CDATA[constant integer   bj_ITEMCODE_STATUS_SELLABLE = 1]]>
    </Variable>

    <Variable Name="bj_ITEMCODE_STATUS_PAWNABLE" Type="integer" Value="2">
      <![CDATA[constant integer   bj_ITEMCODE_STATUS_PAWNABLE = 2]]>
    </Variable>

    <Variable Name="bj_MINIMAPPINGSTYLE_SIMPLE" Type="integer" Value="0">
      <![CDATA[constant integer   bj_MINIMAPPINGSTYLE_SIMPLE  = 0]]>
    </Variable>

    <Variable Name="bj_MINIMAPPINGSTYLE_FLASHY" Type="integer" Value="1">
      <![CDATA[constant integer   bj_MINIMAPPINGSTYLE_FLASHY  = 1]]>
    </Variable>

    <Variable Name="bj_MINIMAPPINGSTYLE_ATTACK" Type="integer" Value="2">
      <![CDATA[constant integer   bj_MINIMAPPINGSTYLE_ATTACK  = 2]]>
    </Variable>

    <Variable Name="bj_CORPSE_MAX_DEATH_TIME" Type="real" Value="8.00">
      <![CDATA[constant real      bj_CORPSE_MAX_DEATH_TIME    = 8.00]]>
    </Variable>

    <Variable Name="bj_CORPSETYPE_FLESH" Type="integer" Value="0">
      <![CDATA[constant integer   bj_CORPSETYPE_FLESH         = 0]]>
    </Variable>

    <Variable Name="bj_CORPSETYPE_BONE" Type="integer" Value="1">
      <![CDATA[constant integer   bj_CORPSETYPE_BONE          = 1]]>
    </Variable>

    <Variable Name="bj_ELEVATOR_BLOCKER_CODE" Type="integer" Value="'DTep'">
      <![CDATA[constant integer   bj_ELEVATOR_BLOCKER_CODE    = 'DTep']]>
    </Variable>

    <Variable Name="bj_ELEVATOR_CODE01" Type="integer" Value="'DTrf'">
      <![CDATA[constant integer   bj_ELEVATOR_CODE01          = 'DTrf']]>
    </Variable>

    <Variable Name="bj_ELEVATOR_CODE02" Type="integer" Value="'DTrx'">
      <![CDATA[constant integer   bj_ELEVATOR_CODE02          = 'DTrx']]>
    </Variable>

    <Variable Name="bj_ELEVATOR_WALL_TYPE_ALL" Type="integer" Value="0">
      <![CDATA[constant integer   bj_ELEVATOR_WALL_TYPE_ALL        = 0]]>
    </Variable>

    <Variable Name="bj_ELEVATOR_WALL_TYPE_EAST" Type="integer" Value="1">
      <![CDATA[constant integer   bj_ELEVATOR_WALL_TYPE_EAST       = 1]]>
    </Variable>

    <Variable Name="bj_ELEVATOR_WALL_TYPE_NORTH" Type="integer" Value="2">
      <![CDATA[constant integer   bj_ELEVATOR_WALL_TYPE_NORTH      = 2]]>
    </Variable>

    <Variable Name="bj_ELEVATOR_WALL_TYPE_SOUTH" Type="integer" Value="3">
      <![CDATA[constant integer   bj_ELEVATOR_WALL_TYPE_SOUTH      = 3]]>
    </Variable>

    <Variable Name="bj_ELEVATOR_WALL_TYPE_WEST" Type="integer" Value="4">
      <![CDATA[constant integer   bj_ELEVATOR_WALL_TYPE_WEST       = 4]]>
    </Variable>

    <Variable Name="bj_FORCE_ALL_PLAYERS" Type="force" Value="null">
      <![CDATA[force              bj_FORCE_ALL_PLAYERS        = null]]>
    </Variable>

    <Variable Name="bj_FORCE_PLAYER" Type="force" Array="True">
      <![CDATA[force array        bj_FORCE_PLAYER]]>
    </Variable>

    <Variable Name="bj_MELEE_MAX_TWINKED_HEROES" Type="integer" Value="0">
      <![CDATA[integer            bj_MELEE_MAX_TWINKED_HEROES = 0]]>
    </Variable>

    <Variable Name="bj_mapInitialPlayableArea" Type="rect" Value="null">
      <![CDATA[rect               bj_mapInitialPlayableArea   = null]]>
    </Variable>

    <Variable Name="bj_mapInitialCameraBounds" Type="rect" Value="null">
      <![CDATA[rect               bj_mapInitialCameraBounds   = null]]>
    </Variable>

    <Variable Name="bj_forLoopAIndex" Type="integer" Value="0">
      <![CDATA[integer            bj_forLoopAIndex            = 0]]>
    </Variable>

    <Variable Name="bj_forLoopBIndex" Type="integer" Value="0">
      <![CDATA[integer            bj_forLoopBIndex            = 0]]>
    </Variable>

    <Variable Name="bj_forLoopAIndexEnd" Type="integer" Value="0">
      <![CDATA[integer            bj_forLoopAIndexEnd         = 0]]>
    </Variable>

    <Variable Name="bj_forLoopBIndexEnd" Type="integer" Value="0">
      <![CDATA[integer            bj_forLoopBIndexEnd         = 0]]>
    </Variable>

    <Variable Name="bj_slotControlReady" Type="boolean" Value="false">
      <![CDATA[boolean            bj_slotControlReady         = false]]>
    </Variable>

    <Variable Name="bj_slotControlUsed" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_slotControlUsed]]>
    </Variable>

    <Variable Name="bj_slotControl" Type="mapcontrol" Array="True">
      <![CDATA[mapcontrol array   bj_slotControl]]>
    </Variable>

    <Variable Name="bj_gameStartedTimer" Type="timer" Value="null">
      <![CDATA[timer              bj_gameStartedTimer         = null]]>
    </Variable>

    <Variable Name="bj_gameStarted" Type="boolean" Value="false">
      <![CDATA[boolean            bj_gameStarted              = false]]>
    </Variable>

    <Variable Name="bj_volumeGroupsTimer" Type="timer" Value="CreateTimer()">
      <![CDATA[timer              bj_volumeGroupsTimer        = CreateTimer()]]>
    </Variable>

    <Variable Name="bj_isSinglePlayer" Type="boolean" Value="false">
      <![CDATA[boolean            bj_isSinglePlayer           = false]]>
    </Variable>

    <Variable Name="bj_dncSoundsDay" Type="trigger" Value="null">
      <![CDATA[trigger            bj_dncSoundsDay             = null]]>
    </Variable>

    <Variable Name="bj_dncSoundsNight" Type="trigger" Value="null">
      <![CDATA[trigger            bj_dncSoundsNight           = null]]>
    </Variable>

    <Variable Name="bj_dayAmbientSound" Type="sound" Value="null">
      <![CDATA[sound              bj_dayAmbientSound          = null]]>
    </Variable>

    <Variable Name="bj_nightAmbientSound" Type="sound" Value="null">
      <![CDATA[sound              bj_nightAmbientSound        = null]]>
    </Variable>

    <Variable Name="bj_dncSoundsDawn" Type="trigger" Value="null">
      <![CDATA[trigger            bj_dncSoundsDawn            = null]]>
    </Variable>

    <Variable Name="bj_dncSoundsDusk" Type="trigger" Value="null">
      <![CDATA[trigger            bj_dncSoundsDusk            = null]]>
    </Variable>

    <Variable Name="bj_dawnSound" Type="sound" Value="null">
      <![CDATA[sound              bj_dawnSound                = null]]>
    </Variable>

    <Variable Name="bj_duskSound" Type="sound" Value="null">
      <![CDATA[sound              bj_duskSound                = null]]>
    </Variable>

    <Variable Name="bj_useDawnDuskSounds" Type="boolean" Value="true">
      <![CDATA[boolean            bj_useDawnDuskSounds        = true]]>
    </Variable>

    <Variable Name="bj_dncIsDaytime" Type="boolean" Value="false">
      <![CDATA[boolean            bj_dncIsDaytime             = false]]>
    </Variable>

    <Variable Name="bj_rescueSound" Type="sound" Value="null">
      <![CDATA[sound              bj_rescueSound              = null]]>
    </Variable>

    <Variable Name="bj_questDiscoveredSound" Type="sound" Value="null">
      <![CDATA[sound              bj_questDiscoveredSound     = null]]>
    </Variable>

    <Variable Name="bj_questUpdatedSound" Type="sound" Value="null">
      <![CDATA[sound              bj_questUpdatedSound        = null]]>
    </Variable>

    <Variable Name="bj_questCompletedSound" Type="sound" Value="null">
      <![CDATA[sound              bj_questCompletedSound      = null]]>
    </Variable>

    <Variable Name="bj_questFailedSound" Type="sound" Value="null">
      <![CDATA[sound              bj_questFailedSound         = null]]>
    </Variable>

    <Variable Name="bj_questHintSound" Type="sound" Value="null">
      <![CDATA[sound              bj_questHintSound           = null]]>
    </Variable>

    <Variable Name="bj_questSecretSound" Type="sound" Value="null">
      <![CDATA[sound              bj_questSecretSound         = null]]>
    </Variable>

    <Variable Name="bj_questItemAcquiredSound" Type="sound" Value="null">
      <![CDATA[sound              bj_questItemAcquiredSound   = null]]>
    </Variable>

    <Variable Name="bj_questWarningSound" Type="sound" Value="null">
      <![CDATA[sound              bj_questWarningSound        = null]]>
    </Variable>

    <Variable Name="bj_victoryDialogSound" Type="sound" Value="null">
      <![CDATA[sound              bj_victoryDialogSound       = null]]>
    </Variable>

    <Variable Name="bj_defeatDialogSound" Type="sound" Value="null">
      <![CDATA[sound              bj_defeatDialogSound        = null]]>
    </Variable>

    <Variable Name="bj_stockItemPurchased" Type="trigger" Value="null">
      <![CDATA[trigger            bj_stockItemPurchased       = null]]>
    </Variable>

    <Variable Name="bj_stockUpdateTimer" Type="timer" Value="null">
      <![CDATA[timer              bj_stockUpdateTimer         = null]]>
    </Variable>

    <Variable Name="bj_stockAllowedPermanent" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_stockAllowedPermanent]]>
    </Variable>

    <Variable Name="bj_stockAllowedCharged" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_stockAllowedCharged]]>
    </Variable>

    <Variable Name="bj_stockAllowedArtifact" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_stockAllowedArtifact]]>
    </Variable>

    <Variable Name="bj_stockPickedItemLevel" Type="integer" Value="0">
      <![CDATA[integer            bj_stockPickedItemLevel     = 0]]>
    </Variable>

    <Variable Name="bj_stockPickedItemType" Type="itemtype">
      <![CDATA[itemtype           bj_stockPickedItemType]]>
    </Variable>

    <Variable Name="bj_meleeVisibilityTrained" Type="trigger" Value="null">
      <![CDATA[trigger            bj_meleeVisibilityTrained   = null]]>
    </Variable>

    <Variable Name="bj_meleeVisibilityIsDay" Type="boolean" Value="true">
      <![CDATA[boolean            bj_meleeVisibilityIsDay     = true]]>
    </Variable>

    <Variable Name="bj_meleeGrantHeroItems" Type="boolean" Value="false">
      <![CDATA[boolean            bj_meleeGrantHeroItems      = false]]>
    </Variable>

    <Variable Name="bj_meleeNearestMineToLoc" Type="location" Value="null">
      <![CDATA[location           bj_meleeNearestMineToLoc    = null]]>
    </Variable>

    <Variable Name="bj_meleeNearestMine" Type="unit" Value="null">
      <![CDATA[unit               bj_meleeNearestMine         = null]]>
    </Variable>

    <Variable Name="bj_meleeNearestMineDist" Type="real" Value="0.00">
      <![CDATA[real               bj_meleeNearestMineDist     = 0.00]]>
    </Variable>

    <Variable Name="bj_meleeGameOver" Type="boolean" Value="false">
      <![CDATA[boolean            bj_meleeGameOver            = false]]>
    </Variable>

    <Variable Name="bj_meleeDefeated" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_meleeDefeated]]>
    </Variable>

    <Variable Name="bj_meleeVictoried" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_meleeVictoried]]>
    </Variable>

    <Variable Name="bj_ghoul" Type="unit" Array="True">
      <![CDATA[unit array         bj_ghoul]]>
    </Variable>

    <Variable Name="bj_crippledTimer" Type="timer" Array="True">
      <![CDATA[timer array        bj_crippledTimer]]>
    </Variable>

    <Variable Name="bj_crippledTimerWindows" Type="timerdialog" Array="True">
      <![CDATA[timerdialog array  bj_crippledTimerWindows]]>
    </Variable>

    <Variable Name="bj_playerIsCrippled" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_playerIsCrippled]]>
    </Variable>

    <Variable Name="bj_playerIsExposed" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_playerIsExposed]]>
    </Variable>

    <Variable Name="bj_finishSoonAllExposed" Type="boolean" Value="false">
      <![CDATA[boolean            bj_finishSoonAllExposed     = false]]>
    </Variable>

    <Variable Name="bj_finishSoonTimerDialog" Type="timerdialog" Value="null">
      <![CDATA[timerdialog        bj_finishSoonTimerDialog    = null]]>
    </Variable>

    <Variable Name="bj_meleeTwinkedHeroes" Type="integer" Array="True">
      <![CDATA[integer array      bj_meleeTwinkedHeroes]]>
    </Variable>

    <Variable Name="bj_rescueUnitBehavior" Type="trigger" Value="null">
      <![CDATA[trigger            bj_rescueUnitBehavior       = null]]>
    </Variable>

    <Variable Name="bj_rescueChangeColorUnit" Type="boolean" Value="true">
      <![CDATA[boolean            bj_rescueChangeColorUnit    = true]]>
    </Variable>

    <Variable Name="bj_rescueChangeColorBldg" Type="boolean" Value="true">
      <![CDATA[boolean            bj_rescueChangeColorBldg    = true]]>
    </Variable>

    <Variable Name="bj_cineSceneEndingTimer" Type="timer" Value="null">
      <![CDATA[timer              bj_cineSceneEndingTimer     = null]]>
    </Variable>

    <Variable Name="bj_cineSceneLastSound" Type="sound" Value="null">
      <![CDATA[sound              bj_cineSceneLastSound       = null]]>
    </Variable>

    <Variable Name="bj_cineSceneBeingSkipped" Type="trigger" Value="null">
      <![CDATA[trigger            bj_cineSceneBeingSkipped    = null]]>
    </Variable>

    <Variable Name="bj_cineModePriorSpeed" Type="gamespeed" Value="MAP_SPEED_NORMAL">
      <![CDATA[gamespeed          bj_cineModePriorSpeed       = MAP_SPEED_NORMAL]]>
    </Variable>

    <Variable Name="bj_cineModePriorFogSetting" Type="boolean" Value="false">
      <![CDATA[boolean            bj_cineModePriorFogSetting  = false]]>
    </Variable>

    <Variable Name="bj_cineModePriorMaskSetting" Type="boolean" Value="false">
      <![CDATA[boolean            bj_cineModePriorMaskSetting = false]]>
    </Variable>

    <Variable Name="bj_cineModeAlreadyIn" Type="boolean" Value="false">
      <![CDATA[boolean            bj_cineModeAlreadyIn        = false]]>
    </Variable>

    <Variable Name="bj_cineModePriorDawnDusk" Type="boolean" Value="false">
      <![CDATA[boolean            bj_cineModePriorDawnDusk    = false]]>
    </Variable>

    <Variable Name="bj_cineModeSavedSeed" Type="integer" Value="0">
      <![CDATA[integer            bj_cineModeSavedSeed        = 0]]>
    </Variable>

    <Variable Name="bj_cineFadeFinishTimer" Type="timer" Value="null">
      <![CDATA[timer              bj_cineFadeFinishTimer      = null]]>
    </Variable>

    <Variable Name="bj_cineFadeContinueTimer" Type="timer" Value="null">
      <![CDATA[timer              bj_cineFadeContinueTimer    = null]]>
    </Variable>

    <Variable Name="bj_cineFadeContinueRed" Type="real" Value="0">
      <![CDATA[real               bj_cineFadeContinueRed      = 0]]>
    </Variable>

    <Variable Name="bj_cineFadeContinueGreen" Type="real" Value="0">
      <![CDATA[real               bj_cineFadeContinueGreen    = 0]]>
    </Variable>

    <Variable Name="bj_cineFadeContinueBlue" Type="real" Value="0">
      <![CDATA[real               bj_cineFadeContinueBlue     = 0]]>
    </Variable>

    <Variable Name="bj_cineFadeContinueTrans" Type="real" Value="0">
      <![CDATA[real               bj_cineFadeContinueTrans    = 0]]>
    </Variable>

    <Variable Name="bj_cineFadeContinueDuration" Type="real" Value="0">
      <![CDATA[real               bj_cineFadeContinueDuration = 0]]>
    </Variable>

    <Variable Name="bj_cineFadeContinueTex" Type="string" Value="">
      <![CDATA[string             bj_cineFadeContinueTex      = ""]]>
    </Variable>

    <Variable Name="bj_queuedExecTotal" Type="integer" Value="0">
      <![CDATA[integer            bj_queuedExecTotal          = 0]]>
    </Variable>

    <Variable Name="bj_queuedExecTriggers" Type="trigger" Array="True">
      <![CDATA[trigger array      bj_queuedExecTriggers]]>
    </Variable>

    <Variable Name="bj_queuedExecUseConds" Type="boolean" Array="True">
      <![CDATA[boolean array      bj_queuedExecUseConds]]>
    </Variable>

    <Variable Name="bj_queuedExecTimeoutTimer" Type="timer" Value="CreateTimer()">
      <![CDATA[timer              bj_queuedExecTimeoutTimer   = CreateTimer()]]>
    </Variable>

    <Variable Name="bj_queuedExecTimeout" Type="trigger" Value="null">
      <![CDATA[trigger            bj_queuedExecTimeout        = null]]>
    </Variable>

    <Variable Name="bj_destInRegionDiesCount" Type="integer" Value="0">
      <![CDATA[integer            bj_destInRegionDiesCount    = 0]]>
    </Variable>

    <Variable Name="bj_destInRegionDiesTrig" Type="trigger" Value="null">
      <![CDATA[trigger            bj_destInRegionDiesTrig     = null]]>
    </Variable>

    <Variable Name="bj_groupCountUnits" Type="integer" Value="0">
      <![CDATA[integer            bj_groupCountUnits          = 0]]>
    </Variable>

    <Variable Name="bj_forceCountPlayers" Type="integer" Value="0">
      <![CDATA[integer            bj_forceCountPlayers        = 0]]>
    </Variable>

    <Variable Name="bj_groupEnumTypeId" Type="integer" Value="0">
      <![CDATA[integer            bj_groupEnumTypeId          = 0]]>
    </Variable>

    <Variable Name="bj_groupEnumOwningPlayer" Type="player" Value="null">
      <![CDATA[player             bj_groupEnumOwningPlayer    = null]]>
    </Variable>

    <Variable Name="bj_groupAddGroupDest" Type="group" Value="null">
      <![CDATA[group              bj_groupAddGroupDest        = null]]>
    </Variable>

    <Variable Name="bj_groupRemoveGroupDest" Type="group" Value="null">
      <![CDATA[group              bj_groupRemoveGroupDest     = null]]>
    </Variable>

    <Variable Name="bj_groupRandomConsidered" Type="integer" Value="0">
      <![CDATA[integer            bj_groupRandomConsidered    = 0]]>
    </Variable>

    <Variable Name="bj_groupRandomCurrentPick" Type="unit" Value="null">
      <![CDATA[unit               bj_groupRandomCurrentPick   = null]]>
    </Variable>

    <Variable Name="bj_groupLastCreatedDest" Type="group" Value="null">
      <![CDATA[group              bj_groupLastCreatedDest     = null]]>
    </Variable>

    <Variable Name="bj_randomSubGroupGroup" Type="group" Value="null">
      <![CDATA[group              bj_randomSubGroupGroup      = null]]>
    </Variable>

    <Variable Name="bj_randomSubGroupWant" Type="integer" Value="0">
      <![CDATA[integer            bj_randomSubGroupWant       = 0]]>
    </Variable>

    <Variable Name="bj_randomSubGroupTotal" Type="integer" Value="0">
      <![CDATA[integer            bj_randomSubGroupTotal      = 0]]>
    </Variable>

    <Variable Name="bj_randomSubGroupChance" Type="real" Value="0">
      <![CDATA[real               bj_randomSubGroupChance     = 0]]>
    </Variable>

    <Variable Name="bj_destRandomConsidered" Type="integer" Value="0">
      <![CDATA[integer            bj_destRandomConsidered     = 0]]>
    </Variable>

    <Variable Name="bj_destRandomCurrentPick" Type="destructable" Value="null">
      <![CDATA[destructable       bj_destRandomCurrentPick    = null]]>
    </Variable>

    <Variable Name="bj_elevatorWallBlocker" Type="destructable" Value="null">
      <![CDATA[destructable       bj_elevatorWallBlocker      = null]]>
    </Variable>

    <Variable Name="bj_elevatorNeighbor" Type="destructable" Value="null">
      <![CDATA[destructable       bj_elevatorNeighbor         = null]]>
    </Variable>

    <Variable Name="bj_itemRandomConsidered" Type="integer" Value="0">
      <![CDATA[integer            bj_itemRandomConsidered     = 0]]>
    </Variable>

    <Variable Name="bj_itemRandomCurrentPick" Type="item" Value="null">
      <![CDATA[item               bj_itemRandomCurrentPick    = null]]>
    </Variable>

    <Variable Name="bj_forceRandomConsidered" Type="integer" Value="0">
      <![CDATA[integer            bj_forceRandomConsidered    = 0]]>
    </Variable>

    <Variable Name="bj_forceRandomCurrentPick" Type="player" Value="null">
      <![CDATA[player             bj_forceRandomCurrentPick   = null]]>
    </Variable>

    <Variable Name="bj_makeUnitRescuableUnit" Type="unit" Value="null">
      <![CDATA[unit               bj_makeUnitRescuableUnit    = null]]>
    </Variable>

    <Variable Name="bj_makeUnitRescuableFlag" Type="boolean" Value="true">
      <![CDATA[boolean            bj_makeUnitRescuableFlag    = true]]>
    </Variable>

    <Variable Name="bj_pauseAllUnitsFlag" Type="boolean" Value="true">
      <![CDATA[boolean            bj_pauseAllUnitsFlag        = true]]>
    </Variable>

    <Variable Name="bj_enumDestructableCenter" Type="location" Value="null">
      <![CDATA[location           bj_enumDestructableCenter   = null]]>
    </Variable>

    <Variable Name="bj_enumDestructableRadius" Type="real" Value="0">
      <![CDATA[real               bj_enumDestructableRadius   = 0]]>
    </Variable>

    <Variable Name="bj_setPlayerTargetColor" Type="playercolor" Value="null">
      <![CDATA[playercolor        bj_setPlayerTargetColor     = null]]>
    </Variable>

    <Variable Name="bj_isUnitGroupDeadResult" Type="boolean" Value="true">
      <![CDATA[boolean            bj_isUnitGroupDeadResult    = true]]>
    </Variable>

    <Variable Name="bj_isUnitGroupEmptyResult" Type="boolean" Value="true">
      <![CDATA[boolean            bj_isUnitGroupEmptyResult   = true]]>
    </Variable>

    <Variable Name="bj_isUnitGroupInRectResult" Type="boolean" Value="true">
      <![CDATA[boolean            bj_isUnitGroupInRectResult  = true]]>
    </Variable>

    <Variable Name="bj_isUnitGroupInRectRect" Type="rect" Value="null">
      <![CDATA[rect               bj_isUnitGroupInRectRect    = null]]>
    </Variable>

    <Variable Name="bj_changeLevelShowScores" Type="boolean" Value="false">
      <![CDATA[boolean            bj_changeLevelShowScores    = false]]>
    </Variable>

    <Variable Name="bj_changeLevelMapName" Type="string" Value="null">
      <![CDATA[string             bj_changeLevelMapName       = null]]>
    </Variable>

    <Variable Name="bj_suspendDecayFleshGroup" Type="group" Value="CreateGroup()">
      <![CDATA[group              bj_suspendDecayFleshGroup   = CreateGroup()]]>
    </Variable>

    <Variable Name="bj_suspendDecayBoneGroup" Type="group" Value="CreateGroup()">
      <![CDATA[group              bj_suspendDecayBoneGroup    = CreateGroup()]]>
    </Variable>

    <Variable Name="bj_delayedSuspendDecayTimer" Type="timer" Value="CreateTimer()">
      <![CDATA[timer              bj_delayedSuspendDecayTimer = CreateTimer()]]>
    </Variable>

    <Variable Name="bj_delayedSuspendDecayTrig" Type="trigger" Value="null">
      <![CDATA[trigger            bj_delayedSuspendDecayTrig  = null]]>
    </Variable>

    <Variable Name="bj_livingPlayerUnitsTypeId" Type="integer" Value="0">
      <![CDATA[integer            bj_livingPlayerUnitsTypeId  = 0]]>
    </Variable>

    <Variable Name="bj_lastDyingWidget" Type="widget" Value="null">
      <![CDATA[widget             bj_lastDyingWidget          = null]]>
    </Variable>

    <Variable Name="bj_randDistCount" Type="integer" Value="0">
      <![CDATA[integer            bj_randDistCount            = 0]]>
    </Variable>

    <Variable Name="bj_randDistID" Type="integer" Array="True">
      <![CDATA[integer array      bj_randDistID]]>
    </Variable>

    <Variable Name="bj_randDistChance" Type="integer" Array="True">
      <![CDATA[integer array      bj_randDistChance]]>
    </Variable>

    <Variable Name="bj_lastCreatedUnit" Type="unit" Value="null">
      <![CDATA[unit               bj_lastCreatedUnit          = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedItem" Type="item" Value="null">
      <![CDATA[item               bj_lastCreatedItem          = null]]>
    </Variable>

    <Variable Name="bj_lastRemovedItem" Type="item" Value="null">
      <![CDATA[item               bj_lastRemovedItem          = null]]>
    </Variable>

    <Variable Name="bj_lastHauntedGoldMine" Type="unit" Value="null">
      <![CDATA[unit               bj_lastHauntedGoldMine      = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedDestructable" Type="destructable" Value="null">
      <![CDATA[destructable       bj_lastCreatedDestructable  = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedGroup" Type="group" Value="CreateGroup()">
      <![CDATA[group              bj_lastCreatedGroup         = CreateGroup()]]>
    </Variable>

    <Variable Name="bj_lastCreatedFogModifier" Type="fogmodifier" Value="null">
      <![CDATA[fogmodifier        bj_lastCreatedFogModifier   = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedEffect" Type="effect" Value="null">
      <![CDATA[effect             bj_lastCreatedEffect        = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedWeatherEffect" Type="weathereffect" Value="null">
      <![CDATA[weathereffect      bj_lastCreatedWeatherEffect = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedTerrainDeformation" Type="terraindeformation" Value="null">
      <![CDATA[terraindeformation bj_lastCreatedTerrainDeformation = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedQuest" Type="quest" Value="null">
      <![CDATA[quest              bj_lastCreatedQuest         = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedQuestItem" Type="questitem" Value="null">
      <![CDATA[questitem          bj_lastCreatedQuestItem     = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedDefeatCondition" Type="defeatcondition" Value="null">
      <![CDATA[defeatcondition    bj_lastCreatedDefeatCondition = null]]>
    </Variable>

    <Variable Name="bj_lastStartedTimer" Type="timer" Value="CreateTimer()">
      <![CDATA[timer              bj_lastStartedTimer         = CreateTimer()]]>
    </Variable>

    <Variable Name="bj_lastCreatedTimerDialog" Type="timerdialog" Value="null">
      <![CDATA[timerdialog        bj_lastCreatedTimerDialog   = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedLeaderboard" Type="leaderboard" Value="null">
      <![CDATA[leaderboard        bj_lastCreatedLeaderboard   = null]]>
    </Variable>

    <Variable Name="bj_lastPlayedSound" Type="sound" Value="null">
      <![CDATA[sound              bj_lastPlayedSound          = null]]>
    </Variable>

    <Variable Name="bj_lastPlayedMusic" Type="string" Value="">
      <![CDATA[string             bj_lastPlayedMusic          = ""]]>
    </Variable>

    <Variable Name="bj_lastTransmissionDuration" Type="real" Value="0">
      <![CDATA[real               bj_lastTransmissionDuration = 0]]>
    </Variable>

    <Variable Name="bj_lastCreatedGameCache" Type="gamecache" Value="null">
      <![CDATA[gamecache          bj_lastCreatedGameCache     = null]]>
    </Variable>

    <Variable Name="bj_lastLoadedUnit" Type="unit" Value="null">
      <![CDATA[unit               bj_lastLoadedUnit           = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedButton" Type="button" Value="null">
      <![CDATA[button             bj_lastCreatedButton        = null]]>
    </Variable>

    <Variable Name="bj_lastReplacedUnit" Type="unit" Value="null">
      <![CDATA[unit               bj_lastReplacedUnit         = null]]>
    </Variable>

    <Variable Name="bj_lastCreatedTextTag" Type="texttag" Value="null">
      <![CDATA[texttag            bj_lastCreatedTextTag       = null]]>
    </Variable>

    <Variable Name="filterIssueHauntOrderAtLocBJ" Type="boolexpr" Value="null">
      <![CDATA[boolexpr           filterIssueHauntOrderAtLocBJ      = null]]>
    </Variable>

    <Variable Name="filterEnumDestructablesInCircleBJ" Type="boolexpr" Value="null">
      <![CDATA[boolexpr           filterEnumDestructablesInCircleBJ = null]]>
    </Variable>

    <Variable Name="filterGetUnitsInRectOfPlayer" Type="boolexpr" Value="null">
      <![CDATA[boolexpr           filterGetUnitsInRectOfPlayer      = null]]>
    </Variable>

    <Variable Name="filterGetUnitsOfTypeIdAll" Type="boolexpr" Value="null">
      <![CDATA[boolexpr           filterGetUnitsOfTypeIdAll         = null]]>
    </Variable>

    <Variable Name="filterGetUnitsOfPlayerAndTypeId" Type="boolexpr" Value="null">
      <![CDATA[boolexpr           filterGetUnitsOfPlayerAndTypeId   = null]]>
    </Variable>

    <Variable Name="filterMeleeTrainedUnitIsHeroBJ" Type="boolexpr" Value="null">
      <![CDATA[boolexpr           filterMeleeTrainedUnitIsHeroBJ    = null]]>
    </Variable>

    <Variable Name="filterLivingPlayerUnitsOfTypeId" Type="boolexpr" Value="null">
      <![CDATA[boolexpr           filterLivingPlayerUnitsOfTypeId   = null]]>
    </Variable>

    <Variable Name="bj_wantDestroyGroup" Type="boolean" Value="false">
      <![CDATA[boolean            bj_wantDestroyGroup         = false]]>
    </Variable>
    
    <Function Name="BJDebugMsg" ReturnType="nothing" ArgumentList="string msg">
      <![CDATA[function BJDebugMsg takes string msg returns nothing
    local integer i = 0
    loop
        call DisplayTimedTextToPlayer(Player(i),0,0,60,msg)
        set i = i + 1
        exitwhen i == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="RMinBJ" ReturnType="real" ArgumentList="real a, real b">
      <![CDATA[function RMinBJ takes real a, real b returns real
    if (a < b) then
        return a
    else
        return b
    endif
endfunction
]]>
    </Function>

    <Function Name="RMaxBJ" ReturnType="real" ArgumentList="real a, real b">
      <![CDATA[function RMaxBJ takes real a, real b returns real
    if (a < b) then
        return b
    else
        return a
    endif
endfunction
]]>
    </Function>

    <Function Name="RAbsBJ" ReturnType="real" ArgumentList="real a">
      <![CDATA[function RAbsBJ takes real a returns real
    if (a >= 0) then
        return a
    else
        return -a
    endif
endfunction
]]>
    </Function>

    <Function Name="RSignBJ" ReturnType="real" ArgumentList="real a">
      <![CDATA[function RSignBJ takes real a returns real
    if (a >= 0.0) then
        return 1.0
    else
        return -1.0
    endif
endfunction
]]>
    </Function>

    <Function Name="IMinBJ" ReturnType="integer" ArgumentList="integer a, integer b">
      <![CDATA[function IMinBJ takes integer a, integer b returns integer
    if (a < b) then
        return a
    else
        return b
    endif
endfunction
]]>
    </Function>

    <Function Name="IMaxBJ" ReturnType="integer" ArgumentList="integer a, integer b">
      <![CDATA[function IMaxBJ takes integer a, integer b returns integer
    if (a < b) then
        return b
    else
        return a
    endif
endfunction
]]>
    </Function>

    <Function Name="IAbsBJ" ReturnType="integer" ArgumentList="integer a">
      <![CDATA[function IAbsBJ takes integer a returns integer
    if (a >= 0) then
        return a
    else
        return -a
    endif
endfunction
]]>
    </Function>

    <Function Name="ISignBJ" ReturnType="integer" ArgumentList="integer a">
      <![CDATA[function ISignBJ takes integer a returns integer
    if (a >= 0) then
        return 1
    else
        return -1
    endif
endfunction
]]>
    </Function>

    <Function Name="SinBJ" ReturnType="real" ArgumentList="real degrees">
      <![CDATA[function SinBJ takes real degrees returns real
    return Sin(degrees * bj_DEGTORAD)
endfunction
]]>
    </Function>

    <Function Name="CosBJ" ReturnType="real" ArgumentList="real degrees">
      <![CDATA[function CosBJ takes real degrees returns real
    return Cos(degrees * bj_DEGTORAD)
endfunction
]]>
    </Function>

    <Function Name="TanBJ" ReturnType="real" ArgumentList="real degrees">
      <![CDATA[function TanBJ takes real degrees returns real
    return Tan(degrees * bj_DEGTORAD)
endfunction
]]>
    </Function>

    <Function Name="AsinBJ" ReturnType="real" ArgumentList="real degrees">
      <![CDATA[function AsinBJ takes real degrees returns real
    return Asin(degrees) * bj_RADTODEG
endfunction
]]>
    </Function>

    <Function Name="AcosBJ" ReturnType="real" ArgumentList="real degrees">
      <![CDATA[function AcosBJ takes real degrees returns real
    return Acos(degrees) * bj_RADTODEG
endfunction
]]>
    </Function>

    <Function Name="AtanBJ" ReturnType="real" ArgumentList="real degrees">
      <![CDATA[function AtanBJ takes real degrees returns real
    return Atan(degrees) * bj_RADTODEG
endfunction
]]>
    </Function>

    <Function Name="Atan2BJ" ReturnType="real" ArgumentList="real y, real x">
      <![CDATA[function Atan2BJ takes real y, real x returns real
    return Atan2(y, x) * bj_RADTODEG
endfunction
]]>
    </Function>

    <Function Name="AngleBetweenPoints" ReturnType="real" ArgumentList="location locA, location locB">
      <![CDATA[function AngleBetweenPoints takes location locA, location locB returns real
    return bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))
endfunction
]]>
    </Function>

    <Function Name="DistanceBetweenPoints" ReturnType="real" ArgumentList="location locA, location locB">
      <![CDATA[function DistanceBetweenPoints takes location locA, location locB returns real
    local real dx = GetLocationX(locB) - GetLocationX(locA)
    local real dy = GetLocationY(locB) - GetLocationY(locA)
    return SquareRoot(dx * dx + dy * dy)
endfunction
]]>
    </Function>

    <Function Name="PolarProjectionBJ" ReturnType="location" ArgumentList="location source, real dist, real angle">
      <![CDATA[function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
    return Location(x, y)
endfunction
]]>
    </Function>

    <Function Name="GetRandomDirectionDeg" ReturnType="real" ArgumentList="nothing">
      <![CDATA[function GetRandomDirectionDeg takes nothing returns real
    return GetRandomReal(0, 360)
endfunction
]]>
    </Function>

    <Function Name="GetRandomPercentageBJ" ReturnType="real" ArgumentList="nothing">
      <![CDATA[function GetRandomPercentageBJ takes nothing returns real
    return GetRandomReal(0, 100)
endfunction
]]>
    </Function>

    <Function Name="GetRandomLocInRect" ReturnType="location" ArgumentList="rect whichRect">
      <![CDATA[function GetRandomLocInRect takes rect whichRect returns location
    return Location(GetRandomReal(GetRectMinX(whichRect), GetRectMaxX(whichRect)), GetRandomReal(GetRectMinY(whichRect), GetRectMaxY(whichRect)))
endfunction
]]>
    </Function>

    <Function Name="ModuloInteger" ReturnType="integer" ArgumentList="integer dividend, integer divisor">
      <![CDATA[function ModuloInteger takes integer dividend, integer divisor returns integer
    local integer modulus = dividend - (dividend / divisor) * divisor

    // If the dividend was negative, the above modulus calculation will
    // be negative, but within (-divisor..0).  We can add (divisor) to
    // shift this result into the desired range of (0..divisor).
    if (modulus < 0) then
        set modulus = modulus + divisor
    endif

    return modulus
endfunction
]]>
    </Function>

    <Function Name="ModuloReal" ReturnType="real" ArgumentList="real dividend, real divisor">
      <![CDATA[function ModuloReal takes real dividend, real divisor returns real
    local real modulus = dividend - I2R(R2I(dividend / divisor)) * divisor

    // If the dividend was negative, the above modulus calculation will
    // be negative, but within (-divisor..0).  We can add (divisor) to
    // shift this result into the desired range of (0..divisor).
    if (modulus < 0) then
        set modulus = modulus + divisor
    endif

    return modulus
endfunction
]]>
    </Function>

    <Function Name="OffsetLocation" ReturnType="location" ArgumentList="location loc, real dx, real dy">
      <![CDATA[function OffsetLocation takes location loc, real dx, real dy returns location
    return Location(GetLocationX(loc) + dx, GetLocationY(loc) + dy)
endfunction
]]>
    </Function>

    <Function Name="OffsetRectBJ" ReturnType="rect" ArgumentList="rect r, real dx, real dy">
      <![CDATA[function OffsetRectBJ takes rect r, real dx, real dy returns rect
    return Rect( GetRectMinX(r) + dx, GetRectMinY(r) + dy, GetRectMaxX(r) + dx, GetRectMaxY(r) + dy )
endfunction
]]>
    </Function>

    <Function Name="RectFromCenterSizeBJ" ReturnType="rect" ArgumentList="location center, real width, real height">
      <![CDATA[function RectFromCenterSizeBJ takes location center, real width, real height returns rect
    local real x = GetLocationX( center )
    local real y = GetLocationY( center )
    return Rect( x - width*0.5, y - height*0.5, x + width*0.5, y + height*0.5 )
endfunction
]]>
    </Function>

    <Function Name="RectContainsCoords" ReturnType="boolean" ArgumentList="rect r, real x, real y">
      <![CDATA[function RectContainsCoords takes rect r, real x, real y returns boolean
    return (GetRectMinX(r) <= x) and (x <= GetRectMaxX(r)) and (GetRectMinY(r) <= y) and (y <= GetRectMaxY(r))
endfunction
]]>
    </Function>

    <Function Name="RectContainsLoc" ReturnType="boolean" ArgumentList="rect r, location loc">
      <![CDATA[function RectContainsLoc takes rect r, location loc returns boolean
    return RectContainsCoords(r, GetLocationX(loc), GetLocationY(loc))
endfunction
]]>
    </Function>

    <Function Name="RectContainsUnit" ReturnType="boolean" ArgumentList="rect r, unit whichUnit">
      <![CDATA[function RectContainsUnit takes rect r, unit whichUnit returns boolean
    return RectContainsCoords(r, GetUnitX(whichUnit), GetUnitY(whichUnit))
endfunction
]]>
    </Function>

    <Function Name="RectContainsItem" ReturnType="boolean" ArgumentList="item whichItem, rect r">
      <![CDATA[function RectContainsItem takes item whichItem, rect r returns boolean
    if (whichItem == null) then
        return false
    endif

    if (IsItemOwned(whichItem)) then
        return false
    endif

    return RectContainsCoords(r, GetItemX(whichItem), GetItemY(whichItem))
endfunction
]]>
    </Function>

    <Function Name="ConditionalTriggerExecute" ReturnType="nothing" ArgumentList="trigger trig">
      <![CDATA[function ConditionalTriggerExecute takes trigger trig returns nothing
    if TriggerEvaluate(trig) then
        call TriggerExecute(trig)
    endif
endfunction
]]>
    </Function>

    <Function Name="TriggerExecuteBJ" ReturnType="boolean" ArgumentList="trigger trig, boolean checkConditions">
      <![CDATA[function TriggerExecuteBJ takes trigger trig, boolean checkConditions returns boolean
    if checkConditions then
        if not (TriggerEvaluate(trig)) then
            return false
        endif
    endif
    call TriggerExecute(trig)
    return true
endfunction
]]>
    </Function>

    <Function Name="PostTriggerExecuteBJ" ReturnType="boolean" ArgumentList="trigger trig, boolean checkConditions">
      <![CDATA[function PostTriggerExecuteBJ takes trigger trig, boolean checkConditions returns boolean
    if checkConditions then
        if not (TriggerEvaluate(trig)) then
            return false
        endif
    endif
    call TriggerRegisterTimerEvent(trig, 0, false)
    return true
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerCheck" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function QueuedTriggerCheck takes nothing returns nothing
    local string s = "TrigQueue Check "
    local integer i

    set i = 0
    loop
        exitwhen i >= bj_queuedExecTotal
        set s = s + "q[" + I2S(i) + "]="
        if (bj_queuedExecTriggers[i] == null) then
            set s = s + "null "
        else
            set s = s + "x "
        endif
        set i = i + 1
    endloop
    set s = s + "(" + I2S(bj_queuedExecTotal) + " total)"
    call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,600,s)
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerGetIndex" ReturnType="integer" ArgumentList="trigger trig">
      <![CDATA[function QueuedTriggerGetIndex takes trigger trig returns integer
    // Determine which, if any, of the queued triggers is being removed.
    local integer index     = 0
    loop
        exitwhen index >= bj_queuedExecTotal
        if (bj_queuedExecTriggers[index] == trig) then
            return index
        endif
        set index = index + 1
    endloop
    return -1
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerRemoveByIndex" ReturnType="boolean" ArgumentList="integer trigIndex">
      <![CDATA[function QueuedTriggerRemoveByIndex takes integer trigIndex returns boolean
    local integer index

    // If the to-be-removed index is out of range, fail.
    if (trigIndex >= bj_queuedExecTotal) then
        return false
    endif

    // Shift all queue entries down to fill in the gap.
    set bj_queuedExecTotal = bj_queuedExecTotal - 1
    set index = trigIndex
    loop
        exitwhen index >= bj_queuedExecTotal
        set bj_queuedExecTriggers[index] = bj_queuedExecTriggers[index + 1]
        set bj_queuedExecUseConds[index] = bj_queuedExecUseConds[index + 1]
        set index = index + 1
    endloop
    return true
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerAttemptExec" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function QueuedTriggerAttemptExec takes nothing returns boolean
    loop
        exitwhen bj_queuedExecTotal == 0

        if TriggerExecuteBJ(bj_queuedExecTriggers[0], bj_queuedExecUseConds[0]) then
            // Timeout the queue if it sits at the front of the queue for too long.
            call TimerStart(bj_queuedExecTimeoutTimer, bj_QUEUED_TRIGGER_TIMEOUT, false, null)
            return true
        endif

        call QueuedTriggerRemoveByIndex(0)
    endloop
    return false
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerAddBJ" ReturnType="boolean" ArgumentList="trigger trig, boolean checkConditions">
      <![CDATA[function QueuedTriggerAddBJ takes trigger trig, boolean checkConditions returns boolean
    // Make sure our queue isn't full.  If it is, return failure.
    if (bj_queuedExecTotal >= bj_MAX_QUEUED_TRIGGERS) then
        return false
    endif

    // Add the trigger to an array of to-be-executed triggers.
    set bj_queuedExecTriggers[bj_queuedExecTotal] = trig
    set bj_queuedExecUseConds[bj_queuedExecTotal] = checkConditions
    set bj_queuedExecTotal = bj_queuedExecTotal + 1

    // If this is the only trigger in the queue, run it.
    if (bj_queuedExecTotal == 1) then
        call QueuedTriggerAttemptExec()
    endif
    return true
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerRemoveBJ" ReturnType="nothing" ArgumentList="trigger trig">
      <![CDATA[function QueuedTriggerRemoveBJ takes trigger trig returns nothing
    local integer index
    local integer trigIndex
    local boolean trigExecuted

    // Find the trigger's index.
    set trigIndex = QueuedTriggerGetIndex(trig)
    if (trigIndex == -1) then
        return
    endif

    // Shuffle the other trigger entries down to fill in the gap.
    call QueuedTriggerRemoveByIndex(trigIndex)

    // If we just axed the currently running trigger, run the next one.
    if (trigIndex == 0) then
        call PauseTimer(bj_queuedExecTimeoutTimer)
        call QueuedTriggerAttemptExec()
    endif
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerDoneBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function QueuedTriggerDoneBJ takes nothing returns nothing
    local integer index

    // Make sure there's something on the queue to remove.
    if (bj_queuedExecTotal <= 0) then
        return
    endif

    // Remove the currently running trigger from the array.
    call QueuedTriggerRemoveByIndex(0)

    // If other triggers are waiting to run, run one of them.
    call PauseTimer(bj_queuedExecTimeoutTimer)
    call QueuedTriggerAttemptExec()
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerClearBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function QueuedTriggerClearBJ takes nothing returns nothing
    call PauseTimer(bj_queuedExecTimeoutTimer)
    set bj_queuedExecTotal = 0
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerClearInactiveBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function QueuedTriggerClearInactiveBJ takes nothing returns nothing
    set bj_queuedExecTotal = IMinBJ(bj_queuedExecTotal, 1)
endfunction
]]>
    </Function>

    <Function Name="QueuedTriggerCountBJ" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[function QueuedTriggerCountBJ takes nothing returns integer
    return bj_queuedExecTotal
endfunction
]]>
    </Function>

    <Function Name="IsTriggerQueueEmptyBJ" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function IsTriggerQueueEmptyBJ takes nothing returns boolean
    return bj_queuedExecTotal <= 0
endfunction
]]>
    </Function>

    <Function Name="IsTriggerQueuedBJ" ReturnType="boolean" ArgumentList="trigger trig">
      <![CDATA[function IsTriggerQueuedBJ takes trigger trig returns boolean
    return QueuedTriggerGetIndex(trig) != -1
endfunction
]]>
    </Function>

    <Function Name="GetForLoopIndexA" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[function GetForLoopIndexA takes nothing returns integer
    return bj_forLoopAIndex
endfunction
]]>
    </Function>

    <Function Name="SetForLoopIndexA" ReturnType="nothing" ArgumentList="integer newIndex">
      <![CDATA[function SetForLoopIndexA takes integer newIndex returns nothing
    set bj_forLoopAIndex = newIndex
endfunction
]]>
    </Function>

    <Function Name="GetForLoopIndexB" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[function GetForLoopIndexB takes nothing returns integer
    return bj_forLoopBIndex
endfunction
]]>
    </Function>

    <Function Name="SetForLoopIndexB" ReturnType="nothing" ArgumentList="integer newIndex">
      <![CDATA[function SetForLoopIndexB takes integer newIndex returns nothing
    set bj_forLoopBIndex = newIndex
endfunction
]]>
    </Function>

    <Function Name="PolledWait" ReturnType="nothing" ArgumentList="real duration">
      <![CDATA[function PolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0

            // If we have a bit of time left, skip past 10% of the remaining
            // duration instead of checking every interval, to minimize the
            // polling on long waits.
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction
]]>
    </Function>

    <Function Name="IntegerTertiaryOp" ReturnType="integer" ArgumentList="boolean flag, integer valueA, integer valueB">
      <![CDATA[function IntegerTertiaryOp takes boolean flag, integer valueA, integer valueB returns integer
    if flag then
        return valueA
    else
        return valueB
    endif
endfunction
]]>
    </Function>

    <Function Name="DoNothing" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function DoNothing takes nothing returns nothing
endfunction
]]>
    </Function>

    <Function Name="CommentString" ReturnType="nothing" ArgumentList="string commentString">
      <![CDATA[function CommentString takes string commentString returns nothing
endfunction
]]>
    </Function>

    <Function Name="StringIdentity" ReturnType="string" ArgumentList="string theString">
      <![CDATA[function StringIdentity takes string theString returns string
    return theString
endfunction
]]>
    </Function>

    <Function Name="GetBooleanAnd" ReturnType="boolean" ArgumentList="boolean valueA, boolean valueB">
      <![CDATA[function GetBooleanAnd takes boolean valueA, boolean valueB returns boolean
    return valueA and valueB
endfunction
]]>
    </Function>

    <Function Name="GetBooleanOr" ReturnType="boolean" ArgumentList="boolean valueA, boolean valueB">
      <![CDATA[function GetBooleanOr takes boolean valueA, boolean valueB returns boolean
    return valueA or valueB
endfunction
]]>
    </Function>

    <Function Name="PercentToInt" ReturnType="integer" ArgumentList="real percentage, integer max">
      <![CDATA[function PercentToInt takes real percentage, integer max returns integer
    local integer result = R2I(percentage * I2R(max) * 0.01)

    if (result < 0) then
        set result = 0
    elseif (result > max) then
        set result = max
    endif

    return result
endfunction
]]>
    </Function>

    <Function Name="PercentTo255" ReturnType="integer" ArgumentList="real percentage">
      <![CDATA[function PercentTo255 takes real percentage returns integer
    return PercentToInt(percentage, 255)
endfunction
]]>
    </Function>

    <Function Name="GetTimeOfDay" ReturnType="real" ArgumentList="nothing">
      <![CDATA[function GetTimeOfDay takes nothing returns real
    return GetFloatGameState(GAME_STATE_TIME_OF_DAY)
endfunction
]]>
    </Function>

    <Function Name="SetTimeOfDay" ReturnType="nothing" ArgumentList="real whatTime">
      <![CDATA[function SetTimeOfDay takes real whatTime returns nothing
    call SetFloatGameState(GAME_STATE_TIME_OF_DAY, whatTime)
endfunction
]]>
    </Function>

    <Function Name="SetTimeOfDayScalePercentBJ" ReturnType="nothing" ArgumentList="real scalePercent">
      <![CDATA[function SetTimeOfDayScalePercentBJ takes real scalePercent returns nothing
    call SetTimeOfDayScale(scalePercent * 0.01)
endfunction
]]>
    </Function>

    <Function Name="GetTimeOfDayScalePercentBJ" ReturnType="real" ArgumentList="nothing">
      <![CDATA[function GetTimeOfDayScalePercentBJ takes nothing returns real
    return GetTimeOfDayScale() * 100
endfunction
]]>
    </Function>

    <Function Name="PlaySound" ReturnType="nothing" ArgumentList="string soundName">
      <![CDATA[function PlaySound takes string soundName returns nothing
    local sound soundHandle = CreateSound(soundName, false, false, true, 12700, 12700, "")
    call StartSound(soundHandle)
    call KillSoundWhenDone(soundHandle)
endfunction
]]>
    </Function>

    <Function Name="CompareLocationsBJ" ReturnType="boolean" ArgumentList="location A, location B">
      <![CDATA[function CompareLocationsBJ takes location A, location B returns boolean
    return GetLocationX(A) == GetLocationX(B) and GetLocationY(A) == GetLocationY(B)
endfunction
]]>
    </Function>

    <Function Name="CompareRectsBJ" ReturnType="boolean" ArgumentList="rect A, rect B">
      <![CDATA[function CompareRectsBJ takes rect A, rect B returns boolean
    return GetRectMinX(A) == GetRectMinX(B) and GetRectMinY(A) == GetRectMinY(B) and GetRectMaxX(A) == GetRectMaxX(B) and GetRectMaxY(A) == GetRectMaxY(B)
endfunction
]]>
    </Function>

    <Function Name="GetRectFromCircleBJ" ReturnType="rect" ArgumentList="location center, real radius">
      <![CDATA[function GetRectFromCircleBJ takes location center, real radius returns rect
    local real centerX = GetLocationX(center)
    local real centerY = GetLocationY(center)
    return Rect(centerX - radius, centerY - radius, centerX + radius, centerY + radius)
endfunction
]]>
    </Function>

    <Function Name="GetCurrentCameraSetup" ReturnType="camerasetup" ArgumentList="nothing">
      <![CDATA[function GetCurrentCameraSetup takes nothing returns camerasetup
    local camerasetup theCam = CreateCameraSetup()
    local real duration = 0
    call CameraSetupSetField(theCam, CAMERA_FIELD_TARGET_DISTANCE, GetCameraField(CAMERA_FIELD_TARGET_DISTANCE), duration)
    call CameraSetupSetField(theCam, CAMERA_FIELD_FARZ,            GetCameraField(CAMERA_FIELD_FARZ),            duration)
    call CameraSetupSetField(theCam, CAMERA_FIELD_ZOFFSET,         GetCameraField(CAMERA_FIELD_ZOFFSET),         duration)
    call CameraSetupSetField(theCam, CAMERA_FIELD_ANGLE_OF_ATTACK, bj_RADTODEG * GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK), duration)
    call CameraSetupSetField(theCam, CAMERA_FIELD_FIELD_OF_VIEW,   bj_RADTODEG * GetCameraField(CAMERA_FIELD_FIELD_OF_VIEW),   duration)
    call CameraSetupSetField(theCam, CAMERA_FIELD_ROLL,            bj_RADTODEG * GetCameraField(CAMERA_FIELD_ROLL),            duration)
    call CameraSetupSetField(theCam, CAMERA_FIELD_ROTATION,        bj_RADTODEG * GetCameraField(CAMERA_FIELD_ROTATION),        duration)
    call CameraSetupSetDestPosition(theCam, GetCameraTargetPositionX(), GetCameraTargetPositionY(), duration)
    return theCam
endfunction
]]>
    </Function>

    <Function Name="CameraSetupApplyForPlayer" ReturnType="nothing" ArgumentList="boolean doPan, camerasetup whichSetup, player whichPlayer, real duration">
      <![CDATA[function CameraSetupApplyForPlayer takes boolean doPan, camerasetup whichSetup, player whichPlayer, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call CameraSetupApplyForceDuration(whichSetup, doPan, duration)
    endif
endfunction
]]>
    </Function>

    <Function Name="CameraSetupGetFieldSwap" ReturnType="real" ArgumentList="camerafield whichField, camerasetup whichSetup">
      <![CDATA[function CameraSetupGetFieldSwap takes camerafield whichField, camerasetup whichSetup returns real
    return CameraSetupGetField(whichSetup, whichField)
endfunction
]]>
    </Function>

    <Function Name="SetCameraFieldForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, camerafield whichField, real value, real duration">
      <![CDATA[function SetCameraFieldForPlayer takes player whichPlayer, camerafield whichField, real value, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraField(whichField, value, duration)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCameraTargetControllerNoZForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, unit whichUnit, real xoffset, real yoffset, boolean inheritOrientation">
      <![CDATA[function SetCameraTargetControllerNoZForPlayer takes player whichPlayer, unit whichUnit, real xoffset, real yoffset, boolean inheritOrientation returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraTargetController(whichUnit, xoffset, yoffset, inheritOrientation)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCameraPositionForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real x, real y">
      <![CDATA[function SetCameraPositionForPlayer takes player whichPlayer, real x, real y returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraPosition(x, y)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCameraPositionLocForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, location loc">
      <![CDATA[function SetCameraPositionLocForPlayer takes player whichPlayer, location loc returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraPosition(GetLocationX(loc), GetLocationY(loc))
    endif
endfunction
]]>
    </Function>

    <Function Name="RotateCameraAroundLocBJ" ReturnType="nothing" ArgumentList="real degrees, location loc, player whichPlayer, real duration">
      <![CDATA[function RotateCameraAroundLocBJ takes real degrees, location loc, player whichPlayer, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraRotateMode(GetLocationX(loc), GetLocationY(loc), bj_DEGTORAD * degrees, duration)
    endif
endfunction
]]>
    </Function>

    <Function Name="PanCameraToForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real x, real y">
      <![CDATA[function PanCameraToForPlayer takes player whichPlayer, real x, real y returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PanCameraTo(x, y)
    endif
endfunction
]]>
    </Function>

    <Function Name="PanCameraToLocForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, location loc">
      <![CDATA[function PanCameraToLocForPlayer takes player whichPlayer, location loc returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PanCameraTo(GetLocationX(loc), GetLocationY(loc))
    endif
endfunction
]]>
    </Function>

    <Function Name="PanCameraToTimedForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real x, real y, real duration">
      <![CDATA[function PanCameraToTimedForPlayer takes player whichPlayer, real x, real y, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PanCameraToTimed(x, y, duration)
    endif
endfunction
]]>
    </Function>

    <Function Name="PanCameraToTimedLocForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, location loc, real duration">
      <![CDATA[function PanCameraToTimedLocForPlayer takes player whichPlayer, location loc, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
    endif
endfunction
]]>
    </Function>

    <Function Name="PanCameraToTimedLocWithZForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, location loc, real zOffset, real duration">
      <![CDATA[function PanCameraToTimedLocWithZForPlayer takes player whichPlayer, location loc, real zOffset, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PanCameraToTimedWithZ(GetLocationX(loc), GetLocationY(loc), zOffset, duration)
    endif
endfunction
]]>
    </Function>

    <Function Name="SmartCameraPanBJ" ReturnType="nothing" ArgumentList="player whichPlayer, location loc, real duration">
      <![CDATA[function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, GetCameraTargetPositionLoc())
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
            // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
            // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
            // User is close enough, so don't touch the camera.
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCinematicCameraForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, string cameraModelFile">
      <![CDATA[function SetCinematicCameraForPlayer takes player whichPlayer, string cameraModelFile returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCinematicCamera(cameraModelFile)
    endif
endfunction
]]>
    </Function>

    <Function Name="ResetToGameCameraForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real duration">
      <![CDATA[function ResetToGameCameraForPlayer takes player whichPlayer, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ResetToGameCamera(duration)
    endif
endfunction
]]>
    </Function>

    <Function Name="CameraSetSourceNoiseForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real magnitude, real velocity">
      <![CDATA[function CameraSetSourceNoiseForPlayer takes player whichPlayer, real magnitude, real velocity returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call CameraSetSourceNoise(magnitude, velocity)
    endif
endfunction
]]>
    </Function>

    <Function Name="CameraSetTargetNoiseForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real magnitude, real velocity">
      <![CDATA[function CameraSetTargetNoiseForPlayer takes player whichPlayer, real magnitude, real velocity returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call CameraSetTargetNoise(magnitude, velocity)
    endif
endfunction
]]>
    </Function>

    <Function Name="CameraSetEQNoiseForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real magnitude">
      <![CDATA[function CameraSetEQNoiseForPlayer takes player whichPlayer, real magnitude returns nothing
    local real richter = magnitude
    if (richter > 5.0) then
        set richter = 5.0
    endif
    if (richter < 2.0) then
        set richter = 2.0
    endif
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call CameraSetTargetNoiseEx(magnitude*2.0, magnitude*Pow(10,richter),true)
        call CameraSetSourceNoiseEx(magnitude*2.0, magnitude*Pow(10,richter),true)
    endif
endfunction
]]>
    </Function>

    <Function Name="CameraClearNoiseForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function CameraClearNoiseForPlayer takes player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call CameraSetSourceNoise(0, 0)
        call CameraSetTargetNoise(0, 0)
    endif
endfunction
]]>
    </Function>

    <Function Name="GetCurrentCameraBoundsMapRectBJ" ReturnType="rect" ArgumentList="nothing">
      <![CDATA[function GetCurrentCameraBoundsMapRectBJ takes nothing returns rect
    return Rect(GetCameraBoundMinX(), GetCameraBoundMinY(), GetCameraBoundMaxX(), GetCameraBoundMaxY())
endfunction
]]>
    </Function>

    <Function Name="GetCameraBoundsMapRect" ReturnType="rect" ArgumentList="nothing">
      <![CDATA[function GetCameraBoundsMapRect takes nothing returns rect
    return bj_mapInitialCameraBounds
endfunction
]]>
    </Function>

    <Function Name="GetPlayableMapRect" ReturnType="rect" ArgumentList="nothing">
      <![CDATA[function GetPlayableMapRect takes nothing returns rect
    return bj_mapInitialPlayableArea
endfunction
]]>
    </Function>

    <Function Name="GetEntireMapRect" ReturnType="rect" ArgumentList="nothing">
      <![CDATA[function GetEntireMapRect takes nothing returns rect
    return GetWorldBounds()
endfunction
]]>
    </Function>

    <Function Name="SetCameraBoundsToRect" ReturnType="nothing" ArgumentList="rect r">
      <![CDATA[function SetCameraBoundsToRect takes rect r returns nothing
    local real minX = GetRectMinX(r)
    local real minY = GetRectMinY(r)
    local real maxX = GetRectMaxX(r)
    local real maxY = GetRectMaxY(r)
    call SetCameraBounds(minX, minY, minX, maxY, maxX, maxY, maxX, minY)
endfunction
]]>
    </Function>

    <Function Name="SetCameraBoundsToRectForPlayerBJ" ReturnType="nothing" ArgumentList="player whichPlayer, rect r">
      <![CDATA[function SetCameraBoundsToRectForPlayerBJ takes player whichPlayer, rect r returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraBoundsToRect(r)
    endif
endfunction
]]>
    </Function>

    <Function Name="AdjustCameraBoundsBJ" ReturnType="nothing" ArgumentList="integer adjustMethod, real dxWest, real dxEast, real dyNorth, real dySouth">
      <![CDATA[function AdjustCameraBoundsBJ takes integer adjustMethod, real dxWest, real dxEast, real dyNorth, real dySouth returns nothing
    local real minX = 0
    local real minY = 0
    local real maxX = 0
    local real maxY = 0
    local real scale = 0

    if (adjustMethod == bj_CAMERABOUNDS_ADJUST_ADD) then
        set scale = 1
    elseif (adjustMethod == bj_CAMERABOUNDS_ADJUST_SUB) then
        set scale = -1
    else
        // Unrecognized adjustment method - ignore the request.
        return
    endif

    // Adjust the actual camera values
    set minX = GetCameraBoundMinX() - scale * dxWest
    set maxX = GetCameraBoundMaxX() + scale * dxEast
    set minY = GetCameraBoundMinY() - scale * dySouth
    set maxY = GetCameraBoundMaxY() + scale * dyNorth

    // Make sure the camera bounds are still valid.
    if (maxX < minX) then
        set minX = (minX + maxX) * 0.5
        set maxX = minX
    endif
    if (maxY < minY) then
        set minY = (minY + maxY) * 0.5
        set maxY = minY
    endif

    // Apply the new camera values.
    call SetCameraBounds(minX, minY, minX, maxY, maxX, maxY, maxX, minY)
endfunction
]]>
    </Function>

    <Function Name="AdjustCameraBoundsForPlayerBJ" ReturnType="nothing" ArgumentList="integer adjustMethod, player whichPlayer, real dxWest, real dxEast, real dyNorth, real dySouth">
      <![CDATA[function AdjustCameraBoundsForPlayerBJ takes integer adjustMethod, player whichPlayer, real dxWest, real dxEast, real dyNorth, real dySouth returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call AdjustCameraBoundsBJ(adjustMethod, dxWest, dxEast, dyNorth, dySouth)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCameraQuickPositionForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real x, real y">
      <![CDATA[function SetCameraQuickPositionForPlayer takes player whichPlayer, real x, real y returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraQuickPosition(x, y)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCameraQuickPositionLocForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, location loc">
      <![CDATA[function SetCameraQuickPositionLocForPlayer takes player whichPlayer, location loc returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraQuickPosition(GetLocationX(loc), GetLocationY(loc))
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCameraQuickPositionLoc" ReturnType="nothing" ArgumentList="location loc">
      <![CDATA[function SetCameraQuickPositionLoc takes location loc returns nothing
    call SetCameraQuickPosition(GetLocationX(loc), GetLocationY(loc))
endfunction
]]>
    </Function>

    <Function Name="StopCameraForPlayerBJ" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function StopCameraForPlayerBJ takes player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call StopCamera()
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCameraOrientControllerForPlayerBJ" ReturnType="nothing" ArgumentList="player whichPlayer, unit whichUnit, real xoffset, real yoffset">
      <![CDATA[function SetCameraOrientControllerForPlayerBJ takes player whichPlayer, unit whichUnit, real xoffset, real yoffset returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraOrientController(whichUnit, xoffset, yoffset)
    endif
endfunction
]]>
    </Function>

    <Function Name="CameraSetSmoothingFactorBJ" ReturnType="nothing" ArgumentList="real factor">
      <![CDATA[function CameraSetSmoothingFactorBJ takes real factor returns nothing
    call CameraSetSmoothingFactor(factor)
endfunction
]]>
    </Function>

    <Function Name="CameraResetSmoothingFactorBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CameraResetSmoothingFactorBJ takes nothing returns nothing
    call CameraSetSmoothingFactor(0)
endfunction
]]>
    </Function>

    <Function Name="DisplayTextToForce" ReturnType="nothing" ArgumentList="force toForce, string message">
      <![CDATA[function DisplayTextToForce takes force toForce, string message returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, message)
    endif
endfunction
]]>
    </Function>

    <Function Name="DisplayTimedTextToForce" ReturnType="nothing" ArgumentList="force toForce, real duration, string message">
      <![CDATA[function DisplayTimedTextToForce takes force toForce, real duration, string message returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, duration, message)
    endif
endfunction
]]>
    </Function>

    <Function Name="ClearTextMessagesBJ" ReturnType="nothing" ArgumentList="force toForce">
      <![CDATA[function ClearTextMessagesBJ takes force toForce returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearTextMessages()
    endif
endfunction
]]>
    </Function>

    <Function Name="SubStringBJ" ReturnType="string" ArgumentList="string source, integer start, integer end">
      <![CDATA[function SubStringBJ takes string source, integer start, integer end returns string
    return SubString(source, start-1, end)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterTimerEventPeriodic" ReturnType="event" ArgumentList="trigger trig, real timeout">
      <![CDATA[function TriggerRegisterTimerEventPeriodic takes trigger trig, real timeout returns event
    return TriggerRegisterTimerEvent(trig, timeout, true)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterTimerEventSingle" ReturnType="event" ArgumentList="trigger trig, real timeout">
      <![CDATA[function TriggerRegisterTimerEventSingle takes trigger trig, real timeout returns event
    return TriggerRegisterTimerEvent(trig, timeout, false)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterTimerExpireEventBJ" ReturnType="event" ArgumentList="trigger trig, timer t">
      <![CDATA[function TriggerRegisterTimerExpireEventBJ takes trigger trig, timer t returns event
    return TriggerRegisterTimerExpireEvent(trig, t)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterPlayerUnitEventSimple" ReturnType="event" ArgumentList="trigger trig, player whichPlayer, playerunitevent whichEvent">
      <![CDATA[function TriggerRegisterPlayerUnitEventSimple takes trigger trig, player whichPlayer, playerunitevent whichEvent returns event
    return TriggerRegisterPlayerUnitEvent(trig, whichPlayer, whichEvent, null)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterAnyUnitEventBJ" ReturnType="nothing" ArgumentList="trigger trig, playerunitevent whichEvent">
      <![CDATA[function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing
    local integer index

    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterPlayerSelectionEventBJ" ReturnType="event" ArgumentList="trigger trig, player whichPlayer, boolean selected">
      <![CDATA[function TriggerRegisterPlayerSelectionEventBJ takes trigger trig, player whichPlayer, boolean selected returns event
    if selected then
        return TriggerRegisterPlayerUnitEvent(trig, whichPlayer, EVENT_PLAYER_UNIT_SELECTED, null)
    else
        return TriggerRegisterPlayerUnitEvent(trig, whichPlayer, EVENT_PLAYER_UNIT_DESELECTED, null)
    endif
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterPlayerKeyEventBJ" ReturnType="event" ArgumentList="trigger trig, player whichPlayer, integer keType, integer keKey">
      <![CDATA[function TriggerRegisterPlayerKeyEventBJ takes trigger trig, player whichPlayer, integer keType, integer keKey returns event
    if (keType == bj_KEYEVENTTYPE_DEPRESS) then
        // Depress event - find out what key
        if (keKey == bj_KEYEVENTKEY_LEFT) then
            return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_LEFT_DOWN)
        elseif (keKey == bj_KEYEVENTKEY_RIGHT) then
            return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_RIGHT_DOWN)
        elseif (keKey == bj_KEYEVENTKEY_DOWN) then
            return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_DOWN_DOWN)
        elseif (keKey == bj_KEYEVENTKEY_UP) then
            return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_UP_DOWN)
        else
            // Unrecognized key - ignore the request and return failure.
            return null
        endif
    elseif (keType == bj_KEYEVENTTYPE_RELEASE) then
        // Release event - find out what key
        if (keKey == bj_KEYEVENTKEY_LEFT) then
            return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_LEFT_UP)
        elseif (keKey == bj_KEYEVENTKEY_RIGHT) then
            return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_RIGHT_UP)
        elseif (keKey == bj_KEYEVENTKEY_DOWN) then
            return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_DOWN_UP)
        elseif (keKey == bj_KEYEVENTKEY_UP) then
            return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ARROW_UP_UP)
        else
            // Unrecognized key - ignore the request and return failure.
            return null
        endif
    else
        // Unrecognized type - ignore the request and return failure.
        return null
    endif
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterPlayerEventVictory" ReturnType="event" ArgumentList="trigger trig, player whichPlayer">
      <![CDATA[function TriggerRegisterPlayerEventVictory takes trigger trig, player whichPlayer returns event
    return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_VICTORY)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterPlayerEventDefeat" ReturnType="event" ArgumentList="trigger trig, player whichPlayer">
      <![CDATA[function TriggerRegisterPlayerEventDefeat takes trigger trig, player whichPlayer returns event
    return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_DEFEAT)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterPlayerEventAllianceChanged" ReturnType="event" ArgumentList="trigger trig, player whichPlayer">
      <![CDATA[function TriggerRegisterPlayerEventAllianceChanged takes trigger trig, player whichPlayer returns event
    return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_ALLIANCE_CHANGED)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterPlayerEventEndCinematic" ReturnType="event" ArgumentList="trigger trig, player whichPlayer">
      <![CDATA[function TriggerRegisterPlayerEventEndCinematic takes trigger trig, player whichPlayer returns event
    return TriggerRegisterPlayerEvent(trig, whichPlayer, EVENT_PLAYER_END_CINEMATIC)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterGameStateEventTimeOfDay" ReturnType="event" ArgumentList="trigger trig, limitop opcode, real limitval">
      <![CDATA[function TriggerRegisterGameStateEventTimeOfDay takes trigger trig, limitop opcode, real limitval returns event
    return TriggerRegisterGameStateEvent(trig, GAME_STATE_TIME_OF_DAY, opcode, limitval)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterEnterRegionSimple" ReturnType="event" ArgumentList="trigger trig, region whichRegion">
      <![CDATA[function TriggerRegisterEnterRegionSimple takes trigger trig, region whichRegion returns event
    return TriggerRegisterEnterRegion(trig, whichRegion, null)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterLeaveRegionSimple" ReturnType="event" ArgumentList="trigger trig, region whichRegion">
      <![CDATA[function TriggerRegisterLeaveRegionSimple takes trigger trig, region whichRegion returns event
    return TriggerRegisterLeaveRegion(trig, whichRegion, null)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterEnterRectSimple" ReturnType="event" ArgumentList="trigger trig, rect r">
      <![CDATA[function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterLeaveRectSimple" ReturnType="event" ArgumentList="trigger trig, rect r">
      <![CDATA[function TriggerRegisterLeaveRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterLeaveRegion(trig, rectRegion, null)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterDistanceBetweenUnits" ReturnType="event" ArgumentList="trigger trig, unit whichUnit, boolexpr condition, real range">
      <![CDATA[function TriggerRegisterDistanceBetweenUnits takes trigger trig, unit whichUnit, boolexpr condition, real range returns event
    return TriggerRegisterUnitInRange(trig, whichUnit, range, condition)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterUnitInRangeSimple" ReturnType="event" ArgumentList="trigger trig, real range, unit whichUnit">
      <![CDATA[function TriggerRegisterUnitInRangeSimple takes trigger trig, real range, unit whichUnit returns event
    return TriggerRegisterUnitInRange(trig, whichUnit, range, null)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterUnitLifeEvent" ReturnType="event" ArgumentList="trigger trig, unit whichUnit, limitop opcode, real limitval">
      <![CDATA[function TriggerRegisterUnitLifeEvent takes trigger trig, unit whichUnit, limitop opcode, real limitval returns event
    return TriggerRegisterUnitStateEvent(trig, whichUnit, UNIT_STATE_LIFE, opcode, limitval)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterUnitManaEvent" ReturnType="event" ArgumentList="trigger trig, unit whichUnit, limitop opcode, real limitval">
      <![CDATA[function TriggerRegisterUnitManaEvent takes trigger trig, unit whichUnit, limitop opcode, real limitval returns event
    return TriggerRegisterUnitStateEvent(trig, whichUnit, UNIT_STATE_MANA, opcode, limitval)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterDialogEventBJ" ReturnType="event" ArgumentList="trigger trig, dialog whichDialog">
      <![CDATA[function TriggerRegisterDialogEventBJ takes trigger trig, dialog whichDialog returns event
    return TriggerRegisterDialogEvent(trig, whichDialog)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterShowSkillEventBJ" ReturnType="event" ArgumentList="trigger trig">
      <![CDATA[function TriggerRegisterShowSkillEventBJ takes trigger trig returns event
    return TriggerRegisterGameEvent(trig, EVENT_GAME_SHOW_SKILL)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterBuildSubmenuEventBJ" ReturnType="event" ArgumentList="trigger trig">
      <![CDATA[function TriggerRegisterBuildSubmenuEventBJ takes trigger trig returns event
    return TriggerRegisterGameEvent(trig, EVENT_GAME_BUILD_SUBMENU)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterGameLoadedEventBJ" ReturnType="event" ArgumentList="trigger trig">
      <![CDATA[function TriggerRegisterGameLoadedEventBJ takes trigger trig returns event
    return TriggerRegisterGameEvent(trig, EVENT_GAME_LOADED)
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterGameSavedEventBJ" ReturnType="event" ArgumentList="trigger trig">
      <![CDATA[function TriggerRegisterGameSavedEventBJ takes trigger trig returns event
    return TriggerRegisterGameEvent(trig, EVENT_GAME_SAVE)
endfunction
]]>
    </Function>

    <Function Name="RegisterDestDeathInRegionEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function RegisterDestDeathInRegionEnum takes nothing returns nothing
    set bj_destInRegionDiesCount = bj_destInRegionDiesCount + 1
    if (bj_destInRegionDiesCount <= bj_MAX_DEST_IN_REGION_EVENTS) then
        call TriggerRegisterDeathEvent(bj_destInRegionDiesTrig, GetEnumDestructable())
    endif
endfunction
]]>
    </Function>

    <Function Name="TriggerRegisterDestDeathInRegionEvent" ReturnType="event" ArgumentList="trigger trig, rect r">
      <![CDATA[function TriggerRegisterDestDeathInRegionEvent takes trigger trig, rect r returns event
    set bj_destInRegionDiesTrig = trig
    set bj_destInRegionDiesCount = 0
    call EnumDestructablesInRect(r, null, function RegisterDestDeathInRegionEnum)
    return trig
endfunction
]]>
    </Function>

    <Function Name="AddWeatherEffectSaveLast" ReturnType="weathereffect" ArgumentList="rect where, integer effectID">
      <![CDATA[function AddWeatherEffectSaveLast takes rect where, integer effectID returns weathereffect
    set bj_lastCreatedWeatherEffect = AddWeatherEffect(where, effectID)
    return bj_lastCreatedWeatherEffect
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedWeatherEffect" ReturnType="weathereffect" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedWeatherEffect takes nothing returns weathereffect
    return bj_lastCreatedWeatherEffect
endfunction
]]>
    </Function>

    <Function Name="RemoveWeatherEffectBJ" ReturnType="nothing" ArgumentList="weathereffect whichWeatherEffect">
      <![CDATA[function RemoveWeatherEffectBJ takes weathereffect whichWeatherEffect returns nothing
    call RemoveWeatherEffect(whichWeatherEffect)
endfunction
]]>
    </Function>

    <Function Name="TerrainDeformationCraterBJ" ReturnType="terraindeformation" ArgumentList="real duration, boolean permanent, location where, real radius, real depth">
      <![CDATA[function TerrainDeformationCraterBJ takes real duration, boolean permanent, location where, real radius, real depth returns terraindeformation
    set bj_lastCreatedTerrainDeformation = TerrainDeformCrater(GetLocationX(where), GetLocationY(where), radius, depth, R2I(duration * 1000), permanent)
    return bj_lastCreatedTerrainDeformation
endfunction
]]>
    </Function>

    <Function Name="TerrainDeformationRippleBJ" ReturnType="terraindeformation" ArgumentList="real duration, boolean limitNeg, location where, real startRadius, real endRadius, real depth, real wavePeriod, real waveWidth">
      <![CDATA[function TerrainDeformationRippleBJ takes real duration, boolean limitNeg, location where, real startRadius, real endRadius, real depth, real wavePeriod, real waveWidth returns terraindeformation
    local real spaceWave
    local real timeWave
    local real radiusRatio

    if (endRadius <= 0 or waveWidth <= 0 or wavePeriod <= 0) then
        return null
    endif

    set timeWave = 2.0 * duration / wavePeriod
    set spaceWave = 2.0 * endRadius / waveWidth
    set radiusRatio = startRadius / endRadius

    set bj_lastCreatedTerrainDeformation = TerrainDeformRipple(GetLocationX(where), GetLocationY(where), endRadius, depth, R2I(duration * 1000), 1, spaceWave, timeWave, radiusRatio, limitNeg)
    return bj_lastCreatedTerrainDeformation
endfunction
]]>
    </Function>

    <Function Name="TerrainDeformationWaveBJ" ReturnType="terraindeformation" ArgumentList="real duration, location source, location target, real radius, real depth, real trailDelay">
      <![CDATA[function TerrainDeformationWaveBJ takes real duration, location source, location target, real radius, real depth, real trailDelay returns terraindeformation
    local real distance
    local real dirX
    local real dirY
    local real speed

    set distance = DistanceBetweenPoints(source, target)
    if (distance == 0 or duration <= 0) then
        return null
    endif

    set dirX = (GetLocationX(target) - GetLocationX(source)) / distance
    set dirY = (GetLocationY(target) - GetLocationY(source)) / distance
    set speed = distance / duration

    set bj_lastCreatedTerrainDeformation = TerrainDeformWave(GetLocationX(source), GetLocationY(source), dirX, dirY, distance, speed, radius, depth, R2I(trailDelay * 1000), 1)
    return bj_lastCreatedTerrainDeformation
endfunction
]]>
    </Function>

    <Function Name="TerrainDeformationRandomBJ" ReturnType="terraindeformation" ArgumentList="real duration, location where, real radius, real minDelta, real maxDelta, real updateInterval">
      <![CDATA[function TerrainDeformationRandomBJ takes real duration, location where, real radius, real minDelta, real maxDelta, real updateInterval returns terraindeformation
    set bj_lastCreatedTerrainDeformation = TerrainDeformRandom(GetLocationX(where), GetLocationY(where), radius, minDelta, maxDelta, R2I(duration * 1000), R2I(updateInterval * 1000))
    return bj_lastCreatedTerrainDeformation
endfunction
]]>
    </Function>

    <Function Name="TerrainDeformationStopBJ" ReturnType="nothing" ArgumentList="terraindeformation deformation, real duration">
      <![CDATA[function TerrainDeformationStopBJ takes terraindeformation deformation, real duration returns nothing
    call TerrainDeformStop(deformation, R2I(duration * 1000))
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedTerrainDeformation" ReturnType="terraindeformation" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedTerrainDeformation takes nothing returns terraindeformation
    return bj_lastCreatedTerrainDeformation
endfunction
]]>
    </Function>

    <Function Name="GetTerrainCliffLevelBJ" ReturnType="integer" ArgumentList="location where">
      <![CDATA[function GetTerrainCliffLevelBJ takes location where returns integer
    return GetTerrainCliffLevel(GetLocationX(where), GetLocationY(where))
endfunction
]]>
    </Function>

    <Function Name="SetWaterBaseColorBJ" ReturnType="nothing" ArgumentList="real red, real green, real blue, real transparency">
      <![CDATA[function SetWaterBaseColorBJ takes real red, real green, real blue, real transparency returns nothing
    call SetWaterBaseColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="CreateFogModifierRectSimple" ReturnType="fogmodifier" ArgumentList="player whichPlayer, fogstate whichFogState, rect r, boolean afterUnits">
      <![CDATA[function CreateFogModifierRectSimple takes player whichPlayer, fogstate whichFogState, rect r, boolean afterUnits returns fogmodifier
    set bj_lastCreatedFogModifier = CreateFogModifierRect(whichPlayer, whichFogState, r, true, afterUnits)
    return bj_lastCreatedFogModifier
endfunction
]]>
    </Function>

    <Function Name="CreateFogModifierRadiusLocSimple" ReturnType="fogmodifier" ArgumentList="player whichPlayer, fogstate whichFogState, location center, real radius, boolean afterUnits">
      <![CDATA[function CreateFogModifierRadiusLocSimple takes player whichPlayer, fogstate whichFogState, location center, real radius, boolean afterUnits returns fogmodifier
    set bj_lastCreatedFogModifier = CreateFogModifierRadiusLoc(whichPlayer, whichFogState, center, radius, true, afterUnits)
    return bj_lastCreatedFogModifier
endfunction
]]>
    </Function>

    <Function Name="CreateFogModifierRectBJ" ReturnType="fogmodifier" ArgumentList="boolean enabled, player whichPlayer, fogstate whichFogState, rect r">
      <![CDATA[function CreateFogModifierRectBJ takes boolean enabled, player whichPlayer, fogstate whichFogState, rect r returns fogmodifier
    set bj_lastCreatedFogModifier = CreateFogModifierRect(whichPlayer, whichFogState, r, true, false)
    if enabled then
        call FogModifierStart(bj_lastCreatedFogModifier)
    endif
    return bj_lastCreatedFogModifier
endfunction
]]>
    </Function>

    <Function Name="CreateFogModifierRadiusLocBJ" ReturnType="fogmodifier" ArgumentList="boolean enabled, player whichPlayer, fogstate whichFogState, location center, real radius">
      <![CDATA[function CreateFogModifierRadiusLocBJ takes boolean enabled, player whichPlayer, fogstate whichFogState, location center, real radius returns fogmodifier
    set bj_lastCreatedFogModifier = CreateFogModifierRadiusLoc(whichPlayer, whichFogState, center, radius, true, false)
    if enabled then
        call FogModifierStart(bj_lastCreatedFogModifier)
    endif
    return bj_lastCreatedFogModifier
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedFogModifier" ReturnType="fogmodifier" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedFogModifier takes nothing returns fogmodifier
    return bj_lastCreatedFogModifier
endfunction
]]>
    </Function>

    <Function Name="FogEnableOn" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function FogEnableOn takes nothing returns nothing
    call FogEnable(true)
endfunction
]]>
    </Function>

    <Function Name="FogEnableOff" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function FogEnableOff takes nothing returns nothing
    call FogEnable(false)
endfunction
]]>
    </Function>

    <Function Name="FogMaskEnableOn" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function FogMaskEnableOn takes nothing returns nothing
    call FogMaskEnable(true)
endfunction
]]>
    </Function>

    <Function Name="FogMaskEnableOff" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function FogMaskEnableOff takes nothing returns nothing
    call FogMaskEnable(false)
endfunction
]]>
    </Function>

    <Function Name="UseTimeOfDayBJ" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[function UseTimeOfDayBJ takes boolean flag returns nothing
    call SuspendTimeOfDay(not flag)
endfunction
]]>
    </Function>

    <Function Name="SetTerrainFogExBJ" ReturnType="nothing" ArgumentList="integer style, real zstart, real zend, real density, real red, real green, real blue">
      <![CDATA[function SetTerrainFogExBJ takes integer style, real zstart, real zend, real density, real red, real green, real blue returns nothing
    call SetTerrainFogEx(style, zstart, zend, density, red * 0.01, green * 0.01, blue * 0.01)
endfunction
]]>
    </Function>

    <Function Name="ResetTerrainFogBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function ResetTerrainFogBJ takes nothing returns nothing
    call ResetTerrainFog()
endfunction
]]>
    </Function>

    <Function Name="SetDoodadAnimationBJ" ReturnType="nothing" ArgumentList="string animName, integer doodadID, real radius, location center">
      <![CDATA[function SetDoodadAnimationBJ takes string animName, integer doodadID, real radius, location center returns nothing
    call SetDoodadAnimation(GetLocationX(center), GetLocationY(center), radius, doodadID, false, animName, false)
endfunction
]]>
    </Function>

    <Function Name="SetDoodadAnimationRectBJ" ReturnType="nothing" ArgumentList="string animName, integer doodadID, rect r">
      <![CDATA[function SetDoodadAnimationRectBJ takes string animName, integer doodadID, rect r returns nothing
    call SetDoodadAnimationRect(r, doodadID, animName, false)
endfunction
]]>
    </Function>

    <Function Name="AddUnitAnimationPropertiesBJ" ReturnType="nothing" ArgumentList="boolean add, string animProperties, unit whichUnit">
      <![CDATA[function AddUnitAnimationPropertiesBJ takes boolean add, string animProperties, unit whichUnit returns nothing
    call AddUnitAnimationProperties(whichUnit, animProperties, add)
endfunction
]]>
    </Function>

    <Function Name="PlaySoundBJ" ReturnType="nothing" ArgumentList="sound soundHandle">
      <![CDATA[function PlaySoundBJ takes sound soundHandle returns nothing
    set bj_lastPlayedSound = soundHandle
    if (soundHandle != null) then
        call StartSound(soundHandle)
    endif
endfunction
]]>
    </Function>

    <Function Name="StopSoundBJ" ReturnType="nothing" ArgumentList="sound soundHandle, boolean fadeOut">
      <![CDATA[function StopSoundBJ takes sound soundHandle, boolean fadeOut returns nothing
    call StopSound(soundHandle, false, fadeOut)
endfunction
]]>
    </Function>

    <Function Name="SetSoundVolumeBJ" ReturnType="nothing" ArgumentList="sound soundHandle, real volumePercent">
      <![CDATA[function SetSoundVolumeBJ takes sound soundHandle, real volumePercent returns nothing
    call SetSoundVolume(soundHandle, PercentToInt(volumePercent, 127))
endfunction
]]>
    </Function>

    <Function Name="SetSoundOffsetBJ" ReturnType="nothing" ArgumentList="real newOffset, sound soundHandle">
      <![CDATA[function SetSoundOffsetBJ takes real newOffset, sound soundHandle returns nothing
    call SetSoundPlayPosition(soundHandle, R2I(newOffset * 1000))
endfunction
]]>
    </Function>

    <Function Name="SetSoundDistanceCutoffBJ" ReturnType="nothing" ArgumentList="sound soundHandle, real cutoff">
      <![CDATA[function SetSoundDistanceCutoffBJ takes sound soundHandle, real cutoff returns nothing
    call SetSoundDistanceCutoff(soundHandle, cutoff)
endfunction
]]>
    </Function>

    <Function Name="SetSoundPitchBJ" ReturnType="nothing" ArgumentList="sound soundHandle, real pitch">
      <![CDATA[function SetSoundPitchBJ takes sound soundHandle, real pitch returns nothing
    call SetSoundPitch(soundHandle, pitch)
endfunction
]]>
    </Function>

    <Function Name="SetSoundPositionLocBJ" ReturnType="nothing" ArgumentList="sound soundHandle, location loc, real z">
      <![CDATA[function SetSoundPositionLocBJ takes sound soundHandle, location loc, real z returns nothing
    call SetSoundPosition(soundHandle, GetLocationX(loc), GetLocationY(loc), z)
endfunction
]]>
    </Function>

    <Function Name="AttachSoundToUnitBJ" ReturnType="nothing" ArgumentList="sound soundHandle, unit whichUnit">
      <![CDATA[function AttachSoundToUnitBJ takes sound soundHandle, unit whichUnit returns nothing
    call AttachSoundToUnit(soundHandle, whichUnit)
endfunction
]]>
    </Function>

    <Function Name="SetSoundConeAnglesBJ" ReturnType="nothing" ArgumentList="sound soundHandle, real inside, real outside, real outsideVolumePercent">
      <![CDATA[function SetSoundConeAnglesBJ takes sound soundHandle, real inside, real outside, real outsideVolumePercent returns nothing
    call SetSoundConeAngles(soundHandle, inside, outside, PercentToInt(outsideVolumePercent, 127))
endfunction
]]>
    </Function>

    <Function Name="KillSoundWhenDoneBJ" ReturnType="nothing" ArgumentList="sound soundHandle">
      <![CDATA[function KillSoundWhenDoneBJ takes sound soundHandle returns nothing
    call KillSoundWhenDone(soundHandle)
endfunction
]]>
    </Function>

    <Function Name="PlaySoundAtPointBJ" ReturnType="nothing" ArgumentList="sound soundHandle, real volumePercent, location loc, real z">
      <![CDATA[function PlaySoundAtPointBJ takes sound soundHandle, real volumePercent, location loc, real z returns nothing
    call SetSoundPositionLocBJ(soundHandle, loc, z)
    call SetSoundVolumeBJ(soundHandle, volumePercent)
    call PlaySoundBJ(soundHandle)
endfunction
]]>
    </Function>

    <Function Name="PlaySoundOnUnitBJ" ReturnType="nothing" ArgumentList="sound soundHandle, real volumePercent, unit whichUnit">
      <![CDATA[function PlaySoundOnUnitBJ takes sound soundHandle, real volumePercent, unit whichUnit returns nothing
    call AttachSoundToUnitBJ(soundHandle, whichUnit)
    call SetSoundVolumeBJ(soundHandle, volumePercent)
    call PlaySoundBJ(soundHandle)
endfunction
]]>
    </Function>

    <Function Name="PlaySoundFromOffsetBJ" ReturnType="nothing" ArgumentList="sound soundHandle, real volumePercent, real startingOffset">
      <![CDATA[function PlaySoundFromOffsetBJ takes sound soundHandle, real volumePercent, real startingOffset returns nothing
    call SetSoundVolumeBJ(soundHandle, volumePercent)
    call PlaySoundBJ(soundHandle)
    call SetSoundOffsetBJ(startingOffset, soundHandle)
endfunction
]]>
    </Function>

    <Function Name="PlayMusicBJ" ReturnType="nothing" ArgumentList="string musicFileName">
      <![CDATA[function PlayMusicBJ takes string musicFileName returns nothing
    set bj_lastPlayedMusic = musicFileName
    call PlayMusic(musicFileName)
endfunction
]]>
    </Function>

    <Function Name="PlayMusicExBJ" ReturnType="nothing" ArgumentList="string musicFileName, real startingOffset, real fadeInTime">
      <![CDATA[function PlayMusicExBJ takes string musicFileName, real startingOffset, real fadeInTime returns nothing
    set bj_lastPlayedMusic = musicFileName
    call PlayMusicEx(musicFileName, R2I(startingOffset * 1000), R2I(fadeInTime * 1000))
endfunction
]]>
    </Function>

    <Function Name="SetMusicOffsetBJ" ReturnType="nothing" ArgumentList="real newOffset">
      <![CDATA[function SetMusicOffsetBJ takes real newOffset returns nothing
    call SetMusicPlayPosition(R2I(newOffset * 1000))
endfunction
]]>
    </Function>

    <Function Name="PlayThematicMusicBJ" ReturnType="nothing" ArgumentList="string musicName">
      <![CDATA[function PlayThematicMusicBJ takes string musicName returns nothing
    call PlayThematicMusic(musicName)
endfunction
]]>
    </Function>

    <Function Name="PlayThematicMusicExBJ" ReturnType="nothing" ArgumentList="string musicName, real startingOffset">
      <![CDATA[function PlayThematicMusicExBJ takes string musicName, real startingOffset returns nothing
    call PlayThematicMusicEx(musicName, R2I(startingOffset * 1000))
endfunction
]]>
    </Function>

    <Function Name="SetThematicMusicOffsetBJ" ReturnType="nothing" ArgumentList="real newOffset">
      <![CDATA[function SetThematicMusicOffsetBJ takes real newOffset returns nothing
    call SetThematicMusicPlayPosition(R2I(newOffset * 1000))
endfunction
]]>
    </Function>

    <Function Name="EndThematicMusicBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function EndThematicMusicBJ takes nothing returns nothing
    call EndThematicMusic()
endfunction
]]>
    </Function>

    <Function Name="StopMusicBJ" ReturnType="nothing" ArgumentList="boolean fadeOut">
      <![CDATA[function StopMusicBJ takes boolean fadeOut returns nothing
    call StopMusic(fadeOut)
endfunction
]]>
    </Function>

    <Function Name="ResumeMusicBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function ResumeMusicBJ takes nothing returns nothing
    call ResumeMusic()
endfunction
]]>
    </Function>

    <Function Name="SetMusicVolumeBJ" ReturnType="nothing" ArgumentList="real volumePercent">
      <![CDATA[function SetMusicVolumeBJ takes real volumePercent returns nothing
    call SetMusicVolume(PercentToInt(volumePercent, 127))
endfunction
]]>
    </Function>

    <Function Name="GetSoundDurationBJ" ReturnType="real" ArgumentList="sound soundHandle">
      <![CDATA[function GetSoundDurationBJ takes sound soundHandle returns real
    if (soundHandle == null) then
        return bj_NOTHING_SOUND_DURATION
    else
        return I2R(GetSoundDuration(soundHandle)) * 0.001
    endif
endfunction
]]>
    </Function>

    <Function Name="GetSoundFileDurationBJ" ReturnType="real" ArgumentList="string musicFileName">
      <![CDATA[function GetSoundFileDurationBJ takes string musicFileName returns real
    return I2R(GetSoundFileDuration(musicFileName)) * 0.001
endfunction
]]>
    </Function>

    <Function Name="GetLastPlayedSound" ReturnType="sound" ArgumentList="nothing">
      <![CDATA[function GetLastPlayedSound takes nothing returns sound
    return bj_lastPlayedSound
endfunction
]]>
    </Function>

    <Function Name="GetLastPlayedMusic" ReturnType="string" ArgumentList="nothing">
      <![CDATA[function GetLastPlayedMusic takes nothing returns string
    return bj_lastPlayedMusic
endfunction
]]>
    </Function>

    <Function Name="VolumeGroupSetVolumeBJ" ReturnType="nothing" ArgumentList="volumegroup vgroup, real percent">
      <![CDATA[function VolumeGroupSetVolumeBJ takes volumegroup vgroup, real percent returns nothing
    call VolumeGroupSetVolume(vgroup, percent * 0.01)
endfunction
]]>
    </Function>

    <Function Name="SetCineModeVolumeGroupsImmediateBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetCineModeVolumeGroupsImmediateBJ takes nothing returns nothing
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UNITMOVEMENT,  bj_CINEMODE_VOLUME_UNITMOVEMENT)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UNITSOUNDS,    bj_CINEMODE_VOLUME_UNITSOUNDS)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_COMBAT,        bj_CINEMODE_VOLUME_COMBAT)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_SPELLS,        bj_CINEMODE_VOLUME_SPELLS)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UI,            bj_CINEMODE_VOLUME_UI)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_MUSIC,         bj_CINEMODE_VOLUME_MUSIC)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_AMBIENTSOUNDS, bj_CINEMODE_VOLUME_AMBIENTSOUNDS)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_FIRE,          bj_CINEMODE_VOLUME_FIRE)
endfunction
]]>
    </Function>

    <Function Name="SetCineModeVolumeGroupsBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetCineModeVolumeGroupsBJ takes nothing returns nothing
    // Delay the request if it occurs at map init.
    if bj_gameStarted then
        call SetCineModeVolumeGroupsImmediateBJ()
    else
        call TimerStart(bj_volumeGroupsTimer, bj_GAME_STARTED_THRESHOLD, false, function SetCineModeVolumeGroupsImmediateBJ)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetSpeechVolumeGroupsImmediateBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetSpeechVolumeGroupsImmediateBJ takes nothing returns nothing
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UNITMOVEMENT,  bj_SPEECH_VOLUME_UNITMOVEMENT)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UNITSOUNDS,    bj_SPEECH_VOLUME_UNITSOUNDS)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_COMBAT,        bj_SPEECH_VOLUME_COMBAT)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_SPELLS,        bj_SPEECH_VOLUME_SPELLS)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_UI,            bj_SPEECH_VOLUME_UI)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_MUSIC,         bj_SPEECH_VOLUME_MUSIC)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_AMBIENTSOUNDS, bj_SPEECH_VOLUME_AMBIENTSOUNDS)
    call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_FIRE,          bj_SPEECH_VOLUME_FIRE)
endfunction
]]>
    </Function>

    <Function Name="SetSpeechVolumeGroupsBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetSpeechVolumeGroupsBJ takes nothing returns nothing
    // Delay the request if it occurs at map init.
    if bj_gameStarted then
        call SetSpeechVolumeGroupsImmediateBJ()
    else
        call TimerStart(bj_volumeGroupsTimer, bj_GAME_STARTED_THRESHOLD, false, function SetSpeechVolumeGroupsImmediateBJ)
    endif
endfunction
]]>
    </Function>

    <Function Name="VolumeGroupResetImmediateBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function VolumeGroupResetImmediateBJ takes nothing returns nothing
    call VolumeGroupReset()
endfunction
]]>
    </Function>

    <Function Name="VolumeGroupResetBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function VolumeGroupResetBJ takes nothing returns nothing
    // Delay the request if it occurs at map init.
    if bj_gameStarted then
        call VolumeGroupResetImmediateBJ()
    else
        call TimerStart(bj_volumeGroupsTimer, bj_GAME_STARTED_THRESHOLD, false, function VolumeGroupResetImmediateBJ)
    endif
endfunction
]]>
    </Function>

    <Function Name="GetSoundIsPlayingBJ" ReturnType="boolean" ArgumentList="sound soundHandle">
      <![CDATA[function GetSoundIsPlayingBJ takes sound soundHandle returns boolean
    return GetSoundIsLoading(soundHandle) or GetSoundIsPlaying(soundHandle)
endfunction
]]>
    </Function>

    <Function Name="WaitForSoundBJ" ReturnType="nothing" ArgumentList="sound soundHandle, real offset">
      <![CDATA[function WaitForSoundBJ takes sound soundHandle, real offset returns nothing
    call TriggerWaitForSound( soundHandle, offset )
endfunction
]]>
    </Function>

    <Function Name="SetMapMusicIndexedBJ" ReturnType="nothing" ArgumentList="string musicName, integer index">
      <![CDATA[function SetMapMusicIndexedBJ takes string musicName, integer index returns nothing
    call SetMapMusic(musicName, false, index)
endfunction
]]>
    </Function>

    <Function Name="SetMapMusicRandomBJ" ReturnType="nothing" ArgumentList="string musicName">
      <![CDATA[function SetMapMusicRandomBJ takes string musicName returns nothing
    call SetMapMusic(musicName, true, 0)
endfunction
]]>
    </Function>

    <Function Name="ClearMapMusicBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function ClearMapMusicBJ takes nothing returns nothing
    call ClearMapMusic()
endfunction
]]>
    </Function>

    <Function Name="SetStackedSoundBJ" ReturnType="nothing" ArgumentList="boolean add, sound soundHandle, rect r">
      <![CDATA[function SetStackedSoundBJ takes boolean add, sound soundHandle, rect r returns nothing
    local real width = GetRectMaxX(r) - GetRectMinX(r)
    local real height = GetRectMaxY(r) - GetRectMinY(r)

    call SetSoundPosition(soundHandle, GetRectCenterX(r), GetRectCenterY(r), 0)
    if add then
        call RegisterStackedSound(soundHandle, true, width, height)
    else
        call UnregisterStackedSound(soundHandle, true, width, height)
    endif
endfunction
]]>
    </Function>

    <Function Name="StartSoundForPlayerBJ" ReturnType="nothing" ArgumentList="player whichPlayer, sound soundHandle">
      <![CDATA[function StartSoundForPlayerBJ takes player whichPlayer, sound soundHandle returns nothing
    if (whichPlayer == GetLocalPlayer()) then
        call StartSound(soundHandle)
    endif
endfunction
]]>
    </Function>

    <Function Name="VolumeGroupSetVolumeForPlayerBJ" ReturnType="nothing" ArgumentList="player whichPlayer, volumegroup vgroup, real scale">
      <![CDATA[function VolumeGroupSetVolumeForPlayerBJ takes player whichPlayer, volumegroup vgroup, real scale returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        call VolumeGroupSetVolume(vgroup, scale)
    endif
endfunction
]]>
    </Function>

    <Function Name="EnableDawnDusk" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[function EnableDawnDusk takes boolean flag returns nothing
    set bj_useDawnDuskSounds = flag
endfunction
]]>
    </Function>

    <Function Name="IsDawnDuskEnabled" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function IsDawnDuskEnabled takes nothing returns boolean
    return bj_useDawnDuskSounds
endfunction
]]>
    </Function>

    <Function Name="SetAmbientDaySound" ReturnType="nothing" ArgumentList="string inLabel">
      <![CDATA[function SetAmbientDaySound takes string inLabel returns nothing
    local real ToD

    // Stop old sound, if necessary
    if (bj_dayAmbientSound != null) then
        call StopSound(bj_dayAmbientSound, true, true)
    endif

    // Create new sound
    set bj_dayAmbientSound = CreateMIDISound(inLabel, 20, 20)

    // Start the sound if necessary, based on current time
    set ToD = GetTimeOfDay()
    if (ToD >= bj_TOD_DAWN and ToD < bj_TOD_DUSK) then
        call StartSound(bj_dayAmbientSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetAmbientNightSound" ReturnType="nothing" ArgumentList="string inLabel">
      <![CDATA[function SetAmbientNightSound takes string inLabel returns nothing
    local real ToD

    // Stop old sound, if necessary
    if (bj_nightAmbientSound != null) then
        call StopSound(bj_nightAmbientSound, true, true)
    endif

    // Create new sound
    set bj_nightAmbientSound = CreateMIDISound(inLabel, 20, 20)

    // Start the sound if necessary, based on current time
    set ToD = GetTimeOfDay()
    if (ToD < bj_TOD_DAWN or ToD >= bj_TOD_DUSK) then
        call StartSound(bj_nightAmbientSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="AddSpecialEffectLocBJ" ReturnType="effect" ArgumentList="location where, string modelName">
      <![CDATA[function AddSpecialEffectLocBJ takes location where, string modelName returns effect
    set bj_lastCreatedEffect = AddSpecialEffectLoc(modelName, where)
    return bj_lastCreatedEffect
endfunction
]]>
    </Function>

    <Function Name="AddSpecialEffectTargetUnitBJ" ReturnType="effect" ArgumentList="string attachPointName, widget targetWidget, string modelName">
      <![CDATA[function AddSpecialEffectTargetUnitBJ takes string attachPointName, widget targetWidget, string modelName returns effect
    set bj_lastCreatedEffect = AddSpecialEffectTarget(modelName, targetWidget, attachPointName)
    return bj_lastCreatedEffect
endfunction
]]>
    </Function>

    <Function Name="DestroyEffectBJ" ReturnType="nothing" ArgumentList="effect whichEffect">
      <![CDATA[function DestroyEffectBJ takes effect whichEffect returns nothing
    call DestroyEffect(whichEffect)
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedEffectBJ" ReturnType="effect" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedEffectBJ takes nothing returns effect
    return bj_lastCreatedEffect
endfunction
]]>
    </Function>

    <Function Name="GetItemLoc" ReturnType="location" ArgumentList="item whichItem">
      <![CDATA[function GetItemLoc takes item whichItem returns location
    return Location(GetItemX(whichItem), GetItemY(whichItem))
endfunction
]]>
    </Function>

    <Function Name="GetItemLifeBJ" ReturnType="real" ArgumentList="widget whichWidget">
      <![CDATA[function GetItemLifeBJ takes widget whichWidget returns real
    return GetWidgetLife(whichWidget)
endfunction
]]>
    </Function>

    <Function Name="SetItemLifeBJ" ReturnType="nothing" ArgumentList="widget whichWidget, real life">
      <![CDATA[function SetItemLifeBJ takes widget whichWidget, real life returns nothing
    call SetWidgetLife(whichWidget, life)
endfunction
]]>
    </Function>

    <Function Name="AddHeroXPSwapped" ReturnType="nothing" ArgumentList="integer xpToAdd, unit whichHero, boolean showEyeCandy">
      <![CDATA[function AddHeroXPSwapped takes integer xpToAdd, unit whichHero, boolean showEyeCandy returns nothing
    call AddHeroXP(whichHero, xpToAdd, showEyeCandy)
endfunction
]]>
    </Function>

    <Function Name="SetHeroLevelBJ" ReturnType="nothing" ArgumentList="unit whichHero, integer newLevel, boolean showEyeCandy">
      <![CDATA[function SetHeroLevelBJ takes unit whichHero, integer newLevel, boolean showEyeCandy returns nothing
    local integer oldLevel = GetHeroLevel(whichHero)

    if (newLevel > oldLevel) then
        call SetHeroLevel(whichHero, newLevel, showEyeCandy)
    elseif (newLevel < oldLevel) then
        call UnitStripHeroLevel(whichHero, oldLevel - newLevel)
    else
        // No change in level - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="UnitAddItemSwapped" ReturnType="boolean" ArgumentList="item whichItem, unit whichHero">
      <![CDATA[function UnitAddItemSwapped takes item whichItem, unit whichHero returns boolean
    return UnitAddItem(whichHero, whichItem)
endfunction
]]>
    </Function>

    <Function Name="UnitAddItemByIdSwapped" ReturnType="item" ArgumentList="integer itemId, unit whichHero">
      <![CDATA[function UnitAddItemByIdSwapped takes integer itemId, unit whichHero returns item
    // Create the item at the hero's feet first, and then give it to him.
    // This is to ensure that the item will be left at the hero's feet if
    // his inventory is full. 
    set bj_lastCreatedItem = CreateItem(itemId, GetUnitX(whichHero), GetUnitY(whichHero))
    call UnitAddItem(whichHero, bj_lastCreatedItem)
    return bj_lastCreatedItem
endfunction
]]>
    </Function>

    <Function Name="UnitRemoveItemSwapped" ReturnType="nothing" ArgumentList="item whichItem, unit whichHero">
      <![CDATA[function UnitRemoveItemSwapped takes item whichItem, unit whichHero returns nothing
    set bj_lastRemovedItem = whichItem
    call UnitRemoveItem(whichHero, whichItem)
endfunction
]]>
    </Function>

    <Function Name="UnitRemoveItemFromSlotSwapped" ReturnType="item" ArgumentList="integer itemSlot, unit whichHero">
      <![CDATA[function UnitRemoveItemFromSlotSwapped takes integer itemSlot, unit whichHero returns item
    set bj_lastRemovedItem = UnitRemoveItemFromSlot(whichHero, itemSlot-1)
    return bj_lastRemovedItem
endfunction
]]>
    </Function>

    <Function Name="CreateItemLoc" ReturnType="item" ArgumentList="integer itemId, location loc">
      <![CDATA[function CreateItemLoc takes integer itemId, location loc returns item
    set bj_lastCreatedItem = CreateItem(itemId, GetLocationX(loc), GetLocationY(loc))
    return bj_lastCreatedItem
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedItem" ReturnType="item" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedItem takes nothing returns item
    return bj_lastCreatedItem
endfunction
]]>
    </Function>

    <Function Name="GetLastRemovedItem" ReturnType="item" ArgumentList="nothing">
      <![CDATA[function GetLastRemovedItem takes nothing returns item
    return bj_lastRemovedItem
endfunction
]]>
    </Function>

    <Function Name="SetItemPositionLoc" ReturnType="nothing" ArgumentList="item whichItem, location loc">
      <![CDATA[function SetItemPositionLoc takes item whichItem, location loc returns nothing
    call SetItemPosition(whichItem, GetLocationX(loc), GetLocationY(loc))
endfunction
]]>
    </Function>

    <Function Name="GetLearnedSkillBJ" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[function GetLearnedSkillBJ takes nothing returns integer
    return GetLearnedSkill()
endfunction
]]>
    </Function>

    <Function Name="SuspendHeroXPBJ" ReturnType="nothing" ArgumentList="boolean flag, unit whichHero">
      <![CDATA[function SuspendHeroXPBJ takes boolean flag, unit whichHero returns nothing
    call SuspendHeroXP(whichHero, not flag)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerHandicapXPBJ" ReturnType="nothing" ArgumentList="player whichPlayer, real handicapPercent">
      <![CDATA[function SetPlayerHandicapXPBJ takes player whichPlayer, real handicapPercent returns nothing
    call SetPlayerHandicapXP(whichPlayer, handicapPercent * 0.01)
endfunction
]]>
    </Function>

    <Function Name="GetPlayerHandicapXPBJ" ReturnType="real" ArgumentList="player whichPlayer">
      <![CDATA[function GetPlayerHandicapXPBJ takes player whichPlayer returns real
    return GetPlayerHandicapXP(whichPlayer) * 100
endfunction
]]>
    </Function>

    <Function Name="SetPlayerHandicapBJ" ReturnType="nothing" ArgumentList="player whichPlayer, real handicapPercent">
      <![CDATA[function SetPlayerHandicapBJ takes player whichPlayer, real handicapPercent returns nothing
    call SetPlayerHandicap(whichPlayer, handicapPercent * 0.01)
endfunction
]]>
    </Function>

    <Function Name="GetPlayerHandicapBJ" ReturnType="real" ArgumentList="player whichPlayer">
      <![CDATA[function GetPlayerHandicapBJ takes player whichPlayer returns real
    return GetPlayerHandicap(whichPlayer) * 100
endfunction
]]>
    </Function>

    <Function Name="GetHeroStatBJ" ReturnType="integer" ArgumentList="integer whichStat, unit whichHero, boolean includeBonuses">
      <![CDATA[function GetHeroStatBJ takes integer whichStat, unit whichHero, boolean includeBonuses returns integer
    if (whichStat == bj_HEROSTAT_STR) then
        return GetHeroStr(whichHero, includeBonuses)
    elseif (whichStat == bj_HEROSTAT_AGI) then
        return GetHeroAgi(whichHero, includeBonuses)
    elseif (whichStat == bj_HEROSTAT_INT) then
        return GetHeroInt(whichHero, includeBonuses)
    else
        // Unrecognized hero stat - return 0
        return 0
    endif
endfunction
]]>
    </Function>

    <Function Name="SetHeroStat" ReturnType="nothing" ArgumentList="unit whichHero, integer whichStat, integer value">
      <![CDATA[function SetHeroStat takes unit whichHero, integer whichStat, integer value returns nothing
    // Ignore requests for negative hero stats.
    if (value <= 0) then
        return
    endif

    if (whichStat == bj_HEROSTAT_STR) then
        call SetHeroStr(whichHero, value, true)
    elseif (whichStat == bj_HEROSTAT_AGI) then
        call SetHeroAgi(whichHero, value, true)
    elseif (whichStat == bj_HEROSTAT_INT) then
        call SetHeroInt(whichHero, value, true)
    else
        // Unrecognized hero stat - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="ModifyHeroStat" ReturnType="nothing" ArgumentList="integer whichStat, unit whichHero, integer modifyMethod, integer value">
      <![CDATA[function ModifyHeroStat takes integer whichStat, unit whichHero, integer modifyMethod, integer value returns nothing
    if (modifyMethod == bj_MODIFYMETHOD_ADD) then
        call SetHeroStat(whichHero, whichStat, GetHeroStatBJ(whichStat, whichHero, false) + value)
    elseif (modifyMethod == bj_MODIFYMETHOD_SUB) then
        call SetHeroStat(whichHero, whichStat, GetHeroStatBJ(whichStat, whichHero, false) - value)
    elseif (modifyMethod == bj_MODIFYMETHOD_SET) then
        call SetHeroStat(whichHero, whichStat, value)
    else
        // Unrecognized modification method - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="ModifyHeroSkillPoints" ReturnType="boolean" ArgumentList="unit whichHero, integer modifyMethod, integer value">
      <![CDATA[function ModifyHeroSkillPoints takes unit whichHero, integer modifyMethod, integer value returns boolean
    if (modifyMethod == bj_MODIFYMETHOD_ADD) then
        return UnitModifySkillPoints(whichHero, value)
    elseif (modifyMethod == bj_MODIFYMETHOD_SUB) then
        return UnitModifySkillPoints(whichHero, -value)
    elseif (modifyMethod == bj_MODIFYMETHOD_SET) then
        return UnitModifySkillPoints(whichHero, value - GetHeroSkillPoints(whichHero))
    else
        // Unrecognized modification method - ignore the request and return failure.
        return false
    endif
endfunction
]]>
    </Function>

    <Function Name="UnitUseItemDestructable" ReturnType="boolean" ArgumentList="unit whichUnit, item whichItem, widget target">
      <![CDATA[function UnitUseItemDestructable takes unit whichUnit, item whichItem, widget target returns boolean
    return UnitUseItemTarget(whichUnit, whichItem, target)
endfunction
]]>
    </Function>

    <Function Name="UnitUseItemPointLoc" ReturnType="boolean" ArgumentList="unit whichUnit, item whichItem, location loc">
      <![CDATA[function UnitUseItemPointLoc takes unit whichUnit, item whichItem, location loc returns boolean
    return UnitUseItemPoint(whichUnit, whichItem, GetLocationX(loc), GetLocationY(loc))
endfunction
]]>
    </Function>

    <Function Name="UnitItemInSlotBJ" ReturnType="item" ArgumentList="unit whichUnit, integer itemSlot">
      <![CDATA[function UnitItemInSlotBJ takes unit whichUnit, integer itemSlot returns item
    return UnitItemInSlot(whichUnit, itemSlot-1)
endfunction
]]>
    </Function>

    <Function Name="GetInventoryIndexOfItemTypeBJ" ReturnType="integer" ArgumentList="unit whichUnit, integer itemId">
      <![CDATA[function GetInventoryIndexOfItemTypeBJ takes unit whichUnit, integer itemId returns integer
    local integer index
    local item    indexItem

    set index = 0
    loop
        set indexItem = UnitItemInSlot(whichUnit, index)
        if (indexItem != null) and (GetItemTypeId(indexItem) == itemId) then
            return index + 1
        endif

        set index = index + 1
        exitwhen index >= bj_MAX_INVENTORY
    endloop
    return 0
endfunction
]]>
    </Function>

    <Function Name="GetItemOfTypeFromUnitBJ" ReturnType="item" ArgumentList="unit whichUnit, integer itemId">
      <![CDATA[function GetItemOfTypeFromUnitBJ takes unit whichUnit, integer itemId returns item
    local integer index = GetInventoryIndexOfItemTypeBJ(whichUnit, itemId)

    if (index == 0) then
        return null
    else
        return UnitItemInSlot(whichUnit, index - 1)
    endif
endfunction
]]>
    </Function>

    <Function Name="UnitHasItemOfTypeBJ" ReturnType="boolean" ArgumentList="unit whichUnit, integer itemId">
      <![CDATA[function UnitHasItemOfTypeBJ takes unit whichUnit, integer itemId returns boolean
    return GetInventoryIndexOfItemTypeBJ(whichUnit, itemId) > 0
endfunction
]]>
    </Function>

    <Function Name="SetItemInvulnerableBJ" ReturnType="nothing" ArgumentList="item whichItem, boolean flag">
      <![CDATA[function SetItemInvulnerableBJ takes item whichItem, boolean flag returns nothing
    call SetItemInvulnerable(whichItem, flag)
endfunction
]]>
    </Function>

    <Function Name="SetItemDropOnDeathBJ" ReturnType="nothing" ArgumentList="item whichItem, boolean flag">
      <![CDATA[function SetItemDropOnDeathBJ takes item whichItem, boolean flag returns nothing
    call SetItemDropOnDeath(whichItem, flag)
endfunction
]]>
    </Function>

    <Function Name="SetItemDroppableBJ" ReturnType="nothing" ArgumentList="item whichItem, boolean flag">
      <![CDATA[function SetItemDroppableBJ takes item whichItem, boolean flag returns nothing
    call SetItemDroppable(whichItem, flag)
endfunction
]]>
    </Function>

    <Function Name="SetItemPlayerBJ" ReturnType="nothing" ArgumentList="item whichItem, player whichPlayer, boolean changeColor">
      <![CDATA[function SetItemPlayerBJ takes item whichItem, player whichPlayer, boolean changeColor returns nothing
    call SetItemPlayer(whichItem, whichPlayer, changeColor)
endfunction
]]>
    </Function>

    <Function Name="SetItemVisibleBJ" ReturnType="nothing" ArgumentList="boolean show, item whichItem">
      <![CDATA[function SetItemVisibleBJ takes boolean show, item whichItem returns nothing
    call SetItemVisible(whichItem, show)
endfunction
]]>
    </Function>

    <Function Name="IsItemHiddenBJ" ReturnType="boolean" ArgumentList="item whichItem">
      <![CDATA[function IsItemHiddenBJ takes item whichItem returns boolean
    return not IsItemVisible(whichItem)
endfunction
]]>
    </Function>

    <Function Name="ChooseRandomItemBJ" ReturnType="integer" ArgumentList="integer level">
      <![CDATA[function ChooseRandomItemBJ takes integer level returns integer
    return ChooseRandomItem(level)
endfunction
]]>
    </Function>

    <Function Name="ChooseRandomItemExBJ" ReturnType="integer" ArgumentList="integer level, itemtype whichType">
      <![CDATA[function ChooseRandomItemExBJ takes integer level, itemtype whichType returns integer
    return ChooseRandomItemEx(whichType, level)
endfunction
]]>
    </Function>

    <Function Name="ChooseRandomNPBuildingBJ" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[function ChooseRandomNPBuildingBJ takes nothing returns integer
    return ChooseRandomNPBuilding()
endfunction
]]>
    </Function>

    <Function Name="ChooseRandomCreepBJ" ReturnType="integer" ArgumentList="integer level">
      <![CDATA[function ChooseRandomCreepBJ takes integer level returns integer
    return ChooseRandomCreep(level)
endfunction
]]>
    </Function>

    <Function Name="EnumItemsInRectBJ" ReturnType="nothing" ArgumentList="rect r, code actionFunc">
      <![CDATA[function EnumItemsInRectBJ takes rect r, code actionFunc returns nothing
    call EnumItemsInRect(r, null, actionFunc)
endfunction
]]>
    </Function>

    <Function Name="RandomItemInRectBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function RandomItemInRectBJEnum takes nothing returns nothing
    set bj_itemRandomConsidered = bj_itemRandomConsidered + 1
    if (GetRandomInt(1, bj_itemRandomConsidered) == 1) then
        set bj_itemRandomCurrentPick = GetEnumItem()
    endif
endfunction
]]>
    </Function>

    <Function Name="RandomItemInRectBJ" ReturnType="item" ArgumentList="rect r, boolexpr filter">
      <![CDATA[function RandomItemInRectBJ takes rect r, boolexpr filter returns item
    set bj_itemRandomConsidered = 0
    set bj_itemRandomCurrentPick = null
    call EnumItemsInRect(r, filter, function RandomItemInRectBJEnum)
    call DestroyBoolExpr(filter)
    return bj_itemRandomCurrentPick
endfunction
]]>
    </Function>

    <Function Name="RandomItemInRectSimpleBJ" ReturnType="item" ArgumentList="rect r">
      <![CDATA[function RandomItemInRectSimpleBJ takes rect r returns item
    return RandomItemInRectBJ(r, null)
endfunction
]]>
    </Function>

    <Function Name="CheckItemStatus" ReturnType="boolean" ArgumentList="item whichItem, integer status">
      <![CDATA[function CheckItemStatus takes item whichItem, integer status returns boolean
    if (status == bj_ITEM_STATUS_HIDDEN) then
        return not IsItemVisible(whichItem)
    elseif (status == bj_ITEM_STATUS_OWNED) then
        return IsItemOwned(whichItem)
    elseif (status == bj_ITEM_STATUS_INVULNERABLE) then
        return IsItemInvulnerable(whichItem)
    elseif (status == bj_ITEM_STATUS_POWERUP) then
        return IsItemPowerup(whichItem)
    elseif (status == bj_ITEM_STATUS_SELLABLE) then
        return IsItemSellable(whichItem)
    elseif (status == bj_ITEM_STATUS_PAWNABLE) then
        return IsItemPawnable(whichItem)
    else
        // Unrecognized status - return false
        return false
    endif
endfunction
]]>
    </Function>

    <Function Name="CheckItemcodeStatus" ReturnType="boolean" ArgumentList="integer itemId, integer status">
      <![CDATA[function CheckItemcodeStatus takes integer itemId, integer status returns boolean
    if (status == bj_ITEMCODE_STATUS_POWERUP) then
        return IsItemIdPowerup(itemId)
    elseif (status == bj_ITEMCODE_STATUS_SELLABLE) then
        return IsItemIdSellable(itemId)
    elseif (status == bj_ITEMCODE_STATUS_PAWNABLE) then
        return IsItemIdPawnable(itemId)
    else
        // Unrecognized status - return false
        return false
    endif
endfunction
]]>
    </Function>

    <Function Name="UnitId2OrderIdBJ" ReturnType="integer" ArgumentList="integer unitId">
      <![CDATA[function UnitId2OrderIdBJ takes integer unitId returns integer
    return unitId
endfunction
]]>
    </Function>

    <Function Name="String2UnitIdBJ" ReturnType="integer" ArgumentList="string unitIdString">
      <![CDATA[function String2UnitIdBJ takes string unitIdString returns integer
    return UnitId(unitIdString)
endfunction
]]>
    </Function>

    <Function Name="UnitId2StringBJ" ReturnType="string" ArgumentList="integer unitId">
      <![CDATA[function UnitId2StringBJ takes integer unitId returns string
    local string unitString = UnitId2String(unitId)

    if (unitString != null) then
        return unitString
    endif

    // The unitId was not recognized - return an empty string.
    return ""
endfunction
]]>
    </Function>

    <Function Name="String2OrderIdBJ" ReturnType="integer" ArgumentList="string orderIdString">
      <![CDATA[function String2OrderIdBJ takes string orderIdString returns integer
    local integer orderId
    
    // Check to see if it's a generic order.
    set orderId = OrderId(orderIdString)
    if (orderId != 0) then
        return orderId
    endif

    // Check to see if it's a (train) unit order.
    set orderId = UnitId(orderIdString)
    if (orderId != 0) then
        return orderId
    endif

    // Unrecognized - return 0
    return 0
endfunction
]]>
    </Function>

    <Function Name="OrderId2StringBJ" ReturnType="string" ArgumentList="integer orderId">
      <![CDATA[function OrderId2StringBJ takes integer orderId returns string
    local string orderString

    // Check to see if it's a generic order.
    set orderString = OrderId2String(orderId)
    if (orderString != null) then
        return orderString
    endif

    // Check to see if it's a (train) unit order.
    set orderString = UnitId2String(orderId)
    if (orderString != null) then
        return orderString
    endif

    // Unrecognized - return an empty string.
    return ""
endfunction
]]>
    </Function>

    <Function Name="GetIssuedOrderIdBJ" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[function GetIssuedOrderIdBJ takes nothing returns integer
    return GetIssuedOrderId()
endfunction
]]>
    </Function>

    <Function Name="GetKillingUnitBJ" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[function GetKillingUnitBJ takes nothing returns unit
    return GetKillingUnit()
endfunction
]]>
    </Function>

    <Function Name="CreateUnitAtLocSaveLast" ReturnType="unit" ArgumentList="player id, integer unitid, location loc, real face">
      <![CDATA[function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif

    return bj_lastCreatedUnit
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedUnit" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedUnit takes nothing returns unit
    return bj_lastCreatedUnit
endfunction
]]>
    </Function>

    <Function Name="CreateNUnitsAtLoc" ReturnType="group" ArgumentList="integer count, integer unitId, player whichPlayer, location loc, real face">
      <![CDATA[function CreateNUnitsAtLoc takes integer count, integer unitId, player whichPlayer, location loc, real face returns group
    call GroupClear(bj_lastCreatedGroup)
    loop
        set count = count - 1
        exitwhen count < 0
        call CreateUnitAtLocSaveLast(whichPlayer, unitId, loc, face)
        call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    return bj_lastCreatedGroup
endfunction
]]>
    </Function>

    <Function Name="CreateNUnitsAtLocFacingLocBJ" ReturnType="group" ArgumentList="integer count, integer unitId, player whichPlayer, location loc, location lookAt">
      <![CDATA[function CreateNUnitsAtLocFacingLocBJ takes integer count, integer unitId, player whichPlayer, location loc, location lookAt returns group
    return CreateNUnitsAtLoc(count, unitId, whichPlayer, loc, AngleBetweenPoints(loc, lookAt))
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedGroupEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedGroupEnum takes nothing returns nothing
    call GroupAddUnit(bj_groupLastCreatedDest, GetEnumUnit())
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedGroup" ReturnType="group" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedGroup takes nothing returns group
    set bj_groupLastCreatedDest = CreateGroup()
    call ForGroup(bj_lastCreatedGroup, function GetLastCreatedGroupEnum)
    return bj_groupLastCreatedDest
endfunction
]]>
    </Function>

    <Function Name="CreateCorpseLocBJ" ReturnType="unit" ArgumentList="integer unitid, player whichPlayer, location loc">
      <![CDATA[function CreateCorpseLocBJ takes integer unitid, player whichPlayer, location loc returns unit
    set bj_lastCreatedUnit = CreateCorpse(whichPlayer, unitid, GetLocationX(loc), GetLocationY(loc), GetRandomReal(0, 360))
    return bj_lastCreatedUnit
endfunction
]]>
    </Function>

    <Function Name="UnitSuspendDecayBJ" ReturnType="nothing" ArgumentList="boolean suspend, unit whichUnit">
      <![CDATA[function UnitSuspendDecayBJ takes boolean suspend, unit whichUnit returns nothing
    call UnitSuspendDecay(whichUnit, suspend)
endfunction
]]>
    </Function>

    <Function Name="DelayedSuspendDecayStopAnimEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function DelayedSuspendDecayStopAnimEnum takes nothing returns nothing
    local unit enumUnit = GetEnumUnit()

    if (GetUnitState(enumUnit, UNIT_STATE_LIFE) <= 0) then
        call SetUnitTimeScale(enumUnit, 0.0001)
    endif
endfunction
]]>
    </Function>

    <Function Name="DelayedSuspendDecayBoneEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function DelayedSuspendDecayBoneEnum takes nothing returns nothing
    local unit enumUnit = GetEnumUnit()

    if (GetUnitState(enumUnit, UNIT_STATE_LIFE) <= 0) then
        call UnitSuspendDecay(enumUnit, true)
        call SetUnitTimeScale(enumUnit, 0.0001)
    endif
endfunction
]]>
    </Function>

    <Function Name="DelayedSuspendDecayFleshEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function DelayedSuspendDecayFleshEnum takes nothing returns nothing
    local unit enumUnit = GetEnumUnit()

    if (GetUnitState(enumUnit, UNIT_STATE_LIFE) <= 0) then
        call UnitSuspendDecay(enumUnit, true)
        call SetUnitTimeScale(enumUnit, 10.0)
        call SetUnitAnimation(enumUnit, "decay flesh")
    endif
endfunction
]]>
    </Function>

    <Function Name="DelayedSuspendDecay" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function DelayedSuspendDecay takes nothing returns nothing
    local group boneGroup
    local group fleshGroup

    // Switch the global unit groups over to local variables and recreate
    // the global versions, so that this function can handle overlapping
    // calls.
    set boneGroup = bj_suspendDecayBoneGroup
    set fleshGroup = bj_suspendDecayFleshGroup
    set bj_suspendDecayBoneGroup = CreateGroup()
    set bj_suspendDecayFleshGroup = CreateGroup()

    call ForGroup(fleshGroup, function DelayedSuspendDecayStopAnimEnum)
    call ForGroup(boneGroup, function DelayedSuspendDecayStopAnimEnum)

    call TriggerSleepAction(bj_CORPSE_MAX_DEATH_TIME)
    call ForGroup(fleshGroup, function DelayedSuspendDecayFleshEnum)
    call ForGroup(boneGroup, function DelayedSuspendDecayBoneEnum)

    call TriggerSleepAction(0.05)
    call ForGroup(fleshGroup, function DelayedSuspendDecayStopAnimEnum)

    call DestroyGroup(boneGroup)
    call DestroyGroup(fleshGroup)
endfunction
]]>
    </Function>

    <Function Name="DelayedSuspendDecayCreate" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function DelayedSuspendDecayCreate takes nothing returns nothing
    set bj_delayedSuspendDecayTrig = CreateTrigger()
    call TriggerRegisterTimerExpireEvent(bj_delayedSuspendDecayTrig, bj_delayedSuspendDecayTimer)
    call TriggerAddAction(bj_delayedSuspendDecayTrig, function DelayedSuspendDecay)
endfunction
]]>
    </Function>

    <Function Name="CreatePermanentCorpseLocBJ" ReturnType="unit" ArgumentList="integer style, integer unitid, player whichPlayer, location loc, real facing">
      <![CDATA[function CreatePermanentCorpseLocBJ takes integer style, integer unitid, player whichPlayer, location loc, real facing returns unit
    set bj_lastCreatedUnit = CreateCorpse(whichPlayer, unitid, GetLocationX(loc), GetLocationY(loc), facing)
    call SetUnitBlendTime(bj_lastCreatedUnit, 0)

    if (style == bj_CORPSETYPE_FLESH) then
        call SetUnitAnimation(bj_lastCreatedUnit, "decay flesh")
        call GroupAddUnit(bj_suspendDecayFleshGroup, bj_lastCreatedUnit)
    elseif (style == bj_CORPSETYPE_BONE) then
        call SetUnitAnimation(bj_lastCreatedUnit, "decay bone")
        call GroupAddUnit(bj_suspendDecayBoneGroup, bj_lastCreatedUnit)
    else
        // Unknown decay style - treat as skeletal.
        call SetUnitAnimation(bj_lastCreatedUnit, "decay bone")
        call GroupAddUnit(bj_suspendDecayBoneGroup, bj_lastCreatedUnit)
    endif

    call TimerStart(bj_delayedSuspendDecayTimer, 0.05, false, null)
    return bj_lastCreatedUnit
endfunction
]]>
    </Function>

    <Function Name="GetUnitStateSwap" ReturnType="real" ArgumentList="unitstate whichState, unit whichUnit">
      <![CDATA[function GetUnitStateSwap takes unitstate whichState, unit whichUnit returns real
    return GetUnitState(whichUnit, whichState)
endfunction
]]>
    </Function>

    <Function Name="GetUnitStatePercent" ReturnType="real" ArgumentList="unit whichUnit, unitstate whichState, unitstate whichMaxState">
      <![CDATA[function GetUnitStatePercent takes unit whichUnit, unitstate whichState, unitstate whichMaxState returns real
    local real value    = GetUnitState(whichUnit, whichState)
    local real maxValue = GetUnitState(whichUnit, whichMaxState)

    // Return 0 for null units.
    if (whichUnit == null) or (maxValue == 0) then
        return 0.0
    endif

    return value / maxValue * 100.0
endfunction
]]>
    </Function>

    <Function Name="GetUnitLifePercent" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[function GetUnitLifePercent takes unit whichUnit returns real
    return GetUnitStatePercent(whichUnit, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE)
endfunction
]]>
    </Function>

    <Function Name="GetUnitManaPercent" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[function GetUnitManaPercent takes unit whichUnit returns real
    return GetUnitStatePercent(whichUnit, UNIT_STATE_MANA, UNIT_STATE_MAX_MANA)
endfunction
]]>
    </Function>

    <Function Name="SelectUnitSingle" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function SelectUnitSingle takes unit whichUnit returns nothing
    call ClearSelection()
    call SelectUnit(whichUnit, true)
endfunction
]]>
    </Function>

    <Function Name="SelectGroupBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SelectGroupBJEnum takes nothing returns nothing
    call SelectUnit( GetEnumUnit(), true )
endfunction
]]>
    </Function>

    <Function Name="SelectGroupBJ" ReturnType="nothing" ArgumentList="group g">
      <![CDATA[function SelectGroupBJ takes group g returns nothing
    call ClearSelection()
    call ForGroup( g, function SelectGroupBJEnum )
endfunction
]]>
    </Function>

    <Function Name="SelectUnitAdd" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function SelectUnitAdd takes unit whichUnit returns nothing
    call SelectUnit(whichUnit, true)
endfunction
]]>
    </Function>

    <Function Name="SelectUnitRemove" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function SelectUnitRemove takes unit whichUnit returns nothing
    call SelectUnit(whichUnit, false)
endfunction
]]>
    </Function>

    <Function Name="ClearSelectionForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function ClearSelectionForPlayer takes player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
    endif
endfunction
]]>
    </Function>

    <Function Name="SelectUnitForPlayerSingle" ReturnType="nothing" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[function SelectUnitForPlayerSingle takes unit whichUnit, player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call SelectUnit(whichUnit, true)
    endif
endfunction
]]>
    </Function>

    <Function Name="SelectGroupForPlayerBJ" ReturnType="nothing" ArgumentList="group g, player whichPlayer">
      <![CDATA[function SelectGroupForPlayerBJ takes group g, player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call ForGroup( g, function SelectGroupBJEnum )
    endif
endfunction
]]>
    </Function>

    <Function Name="SelectUnitAddForPlayer" ReturnType="nothing" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[function SelectUnitAddForPlayer takes unit whichUnit, player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SelectUnit(whichUnit, true)
    endif
endfunction
]]>
    </Function>

    <Function Name="SelectUnitRemoveForPlayer" ReturnType="nothing" ArgumentList="unit whichUnit, player whichPlayer">
      <![CDATA[function SelectUnitRemoveForPlayer takes unit whichUnit, player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SelectUnit(whichUnit, false)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetUnitLifeBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real newValue">
      <![CDATA[function SetUnitLifeBJ takes unit whichUnit, real newValue returns nothing
    call SetUnitState(whichUnit, UNIT_STATE_LIFE, RMaxBJ(0,newValue))
endfunction
]]>
    </Function>

    <Function Name="SetUnitManaBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real newValue">
      <![CDATA[function SetUnitManaBJ takes unit whichUnit, real newValue returns nothing
    call SetUnitState(whichUnit, UNIT_STATE_MANA, RMaxBJ(0,newValue))
endfunction
]]>
    </Function>

    <Function Name="SetUnitLifePercentBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real percent">
      <![CDATA[function SetUnitLifePercentBJ takes unit whichUnit, real percent returns nothing
    call SetUnitState(whichUnit, UNIT_STATE_LIFE, GetUnitState(whichUnit, UNIT_STATE_MAX_LIFE) * RMaxBJ(0,percent) * 0.01)
endfunction
]]>
    </Function>

    <Function Name="SetUnitManaPercentBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real percent">
      <![CDATA[function SetUnitManaPercentBJ takes unit whichUnit, real percent returns nothing
    call SetUnitState(whichUnit, UNIT_STATE_MANA, GetUnitState(whichUnit, UNIT_STATE_MAX_MANA) * RMaxBJ(0,percent) * 0.01)
endfunction
]]>
    </Function>

    <Function Name="IsUnitDeadBJ" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function IsUnitDeadBJ takes unit whichUnit returns boolean
    return GetUnitState(whichUnit, UNIT_STATE_LIFE) <= 0
endfunction
]]>
    </Function>

    <Function Name="IsUnitAliveBJ" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function IsUnitAliveBJ takes unit whichUnit returns boolean
    return not IsUnitDeadBJ(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="IsUnitGroupDeadBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function IsUnitGroupDeadBJEnum takes nothing returns nothing
    if not IsUnitDeadBJ(GetEnumUnit()) then
        set bj_isUnitGroupDeadResult = false
    endif
endfunction
]]>
    </Function>

    <Function Name="IsUnitGroupDeadBJ" ReturnType="boolean" ArgumentList="group g">
      <![CDATA[function IsUnitGroupDeadBJ takes group g returns boolean
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_isUnitGroupDeadResult = true
    call ForGroup(g, function IsUnitGroupDeadBJEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_isUnitGroupDeadResult
endfunction
]]>
    </Function>

    <Function Name="IsUnitGroupEmptyBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function IsUnitGroupEmptyBJEnum takes nothing returns nothing
    set bj_isUnitGroupEmptyResult = false
endfunction
]]>
    </Function>

    <Function Name="IsUnitGroupEmptyBJ" ReturnType="boolean" ArgumentList="group g">
      <![CDATA[function IsUnitGroupEmptyBJ takes group g returns boolean
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_isUnitGroupEmptyResult = true
    call ForGroup(g, function IsUnitGroupEmptyBJEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_isUnitGroupEmptyResult
endfunction
]]>
    </Function>

    <Function Name="IsUnitGroupInRectBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function IsUnitGroupInRectBJEnum takes nothing returns nothing
    if not RectContainsUnit(bj_isUnitGroupInRectRect, GetEnumUnit()) then
        set bj_isUnitGroupInRectResult = false
    endif
endfunction
]]>
    </Function>

    <Function Name="IsUnitGroupInRectBJ" ReturnType="boolean" ArgumentList="group g, rect r">
      <![CDATA[function IsUnitGroupInRectBJ takes group g, rect r returns boolean
    set bj_isUnitGroupInRectResult = true
    set bj_isUnitGroupInRectRect = r
    call ForGroup(g, function IsUnitGroupInRectBJEnum)
    return bj_isUnitGroupInRectResult
endfunction
]]>
    </Function>

    <Function Name="IsUnitHiddenBJ" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function IsUnitHiddenBJ takes unit whichUnit returns boolean
    return IsUnitHidden(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="ShowUnitHide" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function ShowUnitHide takes unit whichUnit returns nothing
    call ShowUnit(whichUnit, false)
endfunction
]]>
    </Function>

    <Function Name="ShowUnitShow" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function ShowUnitShow takes unit whichUnit returns nothing
    // Prevent dead heroes from being unhidden.
    if (IsUnitType(whichUnit, UNIT_TYPE_HERO) and IsUnitDeadBJ(whichUnit)) then
        return
    endif

    call ShowUnit(whichUnit, true)
endfunction
]]>
    </Function>

    <Function Name="IssueHauntOrderAtLocBJFilter" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function IssueHauntOrderAtLocBJFilter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == 'ngol'
endfunction
]]>
    </Function>

    <Function Name="IssueHauntOrderAtLocBJ" ReturnType="boolean" ArgumentList="unit whichPeon, location loc">
      <![CDATA[function IssueHauntOrderAtLocBJ takes unit whichPeon, location loc returns boolean
    local group g = null
    local unit goldMine = null

    // Search for a gold mine within a 1-cell radius of the specified location.
    set g = CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(g, loc, 2*bj_CELLWIDTH, filterIssueHauntOrderAtLocBJ)
    set goldMine = FirstOfGroup(g)
    call DestroyGroup(g)

    // If no mine was found, abort the request.
    if (goldMine == null) then
        return false
    endif

    // Issue the Haunt Gold Mine order.
    return IssueTargetOrderById(whichPeon, 'ugol', goldMine)
endfunction
]]>
    </Function>

    <Function Name="IssueBuildOrderByIdLocBJ" ReturnType="boolean" ArgumentList="unit whichPeon, integer unitId, location loc">
      <![CDATA[function IssueBuildOrderByIdLocBJ takes unit whichPeon, integer unitId, location loc returns boolean
    if (unitId == 'ugol') then
        return IssueHauntOrderAtLocBJ(whichPeon, loc)
    else
        return IssueBuildOrderById(whichPeon, unitId, GetLocationX(loc), GetLocationY(loc))
    endif
endfunction
]]>
    </Function>

    <Function Name="IssueTrainOrderByIdBJ" ReturnType="boolean" ArgumentList="unit whichUnit, integer unitId">
      <![CDATA[function IssueTrainOrderByIdBJ takes unit whichUnit, integer unitId returns boolean
    return IssueImmediateOrderById(whichUnit, unitId)
endfunction
]]>
    </Function>

    <Function Name="GroupTrainOrderByIdBJ" ReturnType="boolean" ArgumentList="group g, integer unitId">
      <![CDATA[function GroupTrainOrderByIdBJ takes group g, integer unitId returns boolean
    return GroupImmediateOrderById(g, unitId)
endfunction
]]>
    </Function>

    <Function Name="IssueUpgradeOrderByIdBJ" ReturnType="boolean" ArgumentList="unit whichUnit, integer techId">
      <![CDATA[function IssueUpgradeOrderByIdBJ takes unit whichUnit, integer techId returns boolean
    return IssueImmediateOrderById(whichUnit, techId)
endfunction
]]>
    </Function>

    <Function Name="GetAttackedUnitBJ" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[function GetAttackedUnitBJ takes nothing returns unit
    return GetTriggerUnit()
endfunction
]]>
    </Function>

    <Function Name="SetUnitFlyHeightBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real newHeight, real rate">
      <![CDATA[function SetUnitFlyHeightBJ takes unit whichUnit, real newHeight, real rate returns nothing
    call SetUnitFlyHeight(whichUnit, newHeight, rate)
endfunction
]]>
    </Function>

    <Function Name="SetUnitTurnSpeedBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real turnSpeed">
      <![CDATA[function SetUnitTurnSpeedBJ takes unit whichUnit, real turnSpeed returns nothing
    call SetUnitTurnSpeed(whichUnit, turnSpeed)
endfunction
]]>
    </Function>

    <Function Name="SetUnitPropWindowBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real propWindow">
      <![CDATA[function SetUnitPropWindowBJ takes unit whichUnit, real propWindow returns nothing
    local real angle = propWindow
    if (angle <= 0) then
        set angle = 1
    elseif (angle >= 360) then
        set angle = 359
    endif
    set angle = angle * bj_DEGTORAD

    call SetUnitPropWindow(whichUnit, angle)
endfunction
]]>
    </Function>

    <Function Name="GetUnitPropWindowBJ" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[function GetUnitPropWindowBJ takes unit whichUnit returns real
    return GetUnitPropWindow(whichUnit) * bj_RADTODEG
endfunction
]]>
    </Function>

    <Function Name="GetUnitDefaultPropWindowBJ" ReturnType="real" ArgumentList="unit whichUnit">
      <![CDATA[function GetUnitDefaultPropWindowBJ takes unit whichUnit returns real
    return GetUnitDefaultPropWindow(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="SetUnitBlendTimeBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real blendTime">
      <![CDATA[function SetUnitBlendTimeBJ takes unit whichUnit, real blendTime returns nothing
    call SetUnitBlendTime(whichUnit, blendTime)
endfunction
]]>
    </Function>

    <Function Name="SetUnitAcquireRangeBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real acquireRange">
      <![CDATA[function SetUnitAcquireRangeBJ takes unit whichUnit, real acquireRange returns nothing
    call SetUnitAcquireRange(whichUnit, acquireRange)
endfunction
]]>
    </Function>

    <Function Name="UnitSetCanSleepBJ" ReturnType="nothing" ArgumentList="unit whichUnit, boolean canSleep">
      <![CDATA[function UnitSetCanSleepBJ takes unit whichUnit, boolean canSleep returns nothing
    call UnitAddSleep(whichUnit, canSleep)
endfunction
]]>
    </Function>

    <Function Name="UnitCanSleepBJ" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function UnitCanSleepBJ takes unit whichUnit returns boolean
    return UnitCanSleep(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="UnitWakeUpBJ" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function UnitWakeUpBJ takes unit whichUnit returns nothing
    call UnitWakeUp(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="UnitIsSleepingBJ" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function UnitIsSleepingBJ takes unit whichUnit returns boolean
    return UnitIsSleeping(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="WakePlayerUnitsEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function WakePlayerUnitsEnum takes nothing returns nothing
    call UnitWakeUp(GetEnumUnit())
endfunction
]]>
    </Function>

    <Function Name="WakePlayerUnits" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function WakePlayerUnits takes player whichPlayer returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, whichPlayer, null)
    call ForGroup(g, function WakePlayerUnitsEnum)
    call DestroyGroup(g)
endfunction
]]>
    </Function>

    <Function Name="EnableCreepSleepBJ" ReturnType="nothing" ArgumentList="boolean enable">
      <![CDATA[function EnableCreepSleepBJ takes boolean enable returns nothing
    call SetPlayerState(Player(PLAYER_NEUTRAL_AGGRESSIVE), PLAYER_STATE_NO_CREEP_SLEEP, IntegerTertiaryOp(enable, 0, 1))

    // If we're disabling, attempt to wake any already-sleeping creeps.
    if (not enable) then
        call WakePlayerUnits(Player(PLAYER_NEUTRAL_AGGRESSIVE))
    endif
endfunction
]]>
    </Function>

    <Function Name="UnitGenerateAlarms" ReturnType="boolean" ArgumentList="unit whichUnit, boolean generate">
      <![CDATA[function UnitGenerateAlarms takes unit whichUnit, boolean generate returns boolean
    return UnitIgnoreAlarm(whichUnit, not generate)
endfunction
]]>
    </Function>

    <Function Name="DoesUnitGenerateAlarms" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function DoesUnitGenerateAlarms takes unit whichUnit returns boolean
    return not UnitIgnoreAlarmToggled(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="PauseAllUnitsBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function PauseAllUnitsBJEnum takes nothing returns nothing
    call PauseUnit( GetEnumUnit(), bj_pauseAllUnitsFlag )
endfunction
]]>
    </Function>

    <Function Name="PauseAllUnitsBJ" ReturnType="nothing" ArgumentList="boolean pause">
      <![CDATA[function PauseAllUnitsBJ takes boolean pause returns nothing
    local integer index
    local player  indexPlayer
    local group   g

    set bj_pauseAllUnitsFlag = pause
    set g = CreateGroup()
    set index = 0
    loop
        set indexPlayer = Player( index )

        // If this is a computer slot, pause/resume the AI.
        if (GetPlayerController( indexPlayer ) == MAP_CONTROL_COMPUTER) then
            call PauseCompAI( indexPlayer, pause )
        endif

        // Enumerate and unpause every unit owned by the player.
        call GroupEnumUnitsOfPlayer( g, indexPlayer, null )
        call ForGroup( g, function PauseAllUnitsBJEnum )
        call GroupClear( g )

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call DestroyGroup(g)
endfunction
]]>
    </Function>

    <Function Name="PauseUnitBJ" ReturnType="nothing" ArgumentList="boolean pause, unit whichUnit">
      <![CDATA[function PauseUnitBJ takes boolean pause, unit whichUnit returns nothing
    call PauseUnit(whichUnit, pause)
endfunction
]]>
    </Function>

    <Function Name="IsUnitPausedBJ" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function IsUnitPausedBJ takes unit whichUnit returns boolean
    return IsUnitPaused(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="UnitPauseTimedLifeBJ" ReturnType="nothing" ArgumentList="boolean flag, unit whichUnit">
      <![CDATA[function UnitPauseTimedLifeBJ takes boolean flag, unit whichUnit returns nothing
    call UnitPauseTimedLife(whichUnit, flag)
endfunction
]]>
    </Function>

    <Function Name="UnitApplyTimedLifeBJ" ReturnType="nothing" ArgumentList="real duration, integer buffId, unit whichUnit">
      <![CDATA[function UnitApplyTimedLifeBJ takes real duration, integer buffId, unit whichUnit returns nothing
    call UnitApplyTimedLife(whichUnit, buffId, duration)
endfunction
]]>
    </Function>

    <Function Name="UnitShareVisionBJ" ReturnType="nothing" ArgumentList="boolean share, unit whichUnit, player whichPlayer">
      <![CDATA[function UnitShareVisionBJ takes boolean share, unit whichUnit, player whichPlayer returns nothing
    call UnitShareVision(whichUnit, whichPlayer, share)
endfunction
]]>
    </Function>

    <Function Name="UnitRemoveBuffsBJ" ReturnType="nothing" ArgumentList="integer buffType, unit whichUnit">
      <![CDATA[function UnitRemoveBuffsBJ takes integer buffType, unit whichUnit returns nothing
    if (buffType == bj_REMOVEBUFFS_POSITIVE) then
        call UnitRemoveBuffs(whichUnit, true, false)
    elseif (buffType == bj_REMOVEBUFFS_NEGATIVE) then
        call UnitRemoveBuffs(whichUnit, false, true)
    elseif (buffType == bj_REMOVEBUFFS_ALL) then
        call UnitRemoveBuffs(whichUnit, true, true)
    elseif (buffType == bj_REMOVEBUFFS_NONTLIFE) then
        call UnitRemoveBuffsEx(whichUnit, true, true, false, false, false, true, false)
    else
        // Unrecognized dispel type - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="UnitRemoveBuffsExBJ" ReturnType="nothing" ArgumentList="integer polarity, integer resist, unit whichUnit, boolean bTLife, boolean bAura">
      <![CDATA[function UnitRemoveBuffsExBJ takes integer polarity, integer resist, unit whichUnit, boolean bTLife, boolean bAura returns nothing
    local boolean bPos   = (polarity == bj_BUFF_POLARITY_EITHER) or (polarity == bj_BUFF_POLARITY_POSITIVE)
    local boolean bNeg   = (polarity == bj_BUFF_POLARITY_EITHER) or (polarity == bj_BUFF_POLARITY_NEGATIVE)
    local boolean bMagic = (resist == bj_BUFF_RESIST_BOTH) or (resist == bj_BUFF_RESIST_MAGIC)
    local boolean bPhys  = (resist == bj_BUFF_RESIST_BOTH) or (resist == bj_BUFF_RESIST_PHYSICAL)

    call UnitRemoveBuffsEx(whichUnit, bPos, bNeg, bMagic, bPhys, bTLife, bAura, false)
endfunction
]]>
    </Function>

    <Function Name="UnitCountBuffsExBJ" ReturnType="integer" ArgumentList="integer polarity, integer resist, unit whichUnit, boolean bTLife, boolean bAura">
      <![CDATA[function UnitCountBuffsExBJ takes integer polarity, integer resist, unit whichUnit, boolean bTLife, boolean bAura returns integer
    local boolean bPos   = (polarity == bj_BUFF_POLARITY_EITHER) or (polarity == bj_BUFF_POLARITY_POSITIVE)
    local boolean bNeg   = (polarity == bj_BUFF_POLARITY_EITHER) or (polarity == bj_BUFF_POLARITY_NEGATIVE)
    local boolean bMagic = (resist == bj_BUFF_RESIST_BOTH) or (resist == bj_BUFF_RESIST_MAGIC)
    local boolean bPhys  = (resist == bj_BUFF_RESIST_BOTH) or (resist == bj_BUFF_RESIST_PHYSICAL)

    return UnitCountBuffsEx(whichUnit, bPos, bNeg, bMagic, bPhys, bTLife, bAura, false)
endfunction
]]>
    </Function>

    <Function Name="UnitRemoveAbilityBJ" ReturnType="boolean" ArgumentList="integer abilityId, unit whichUnit">
      <![CDATA[function UnitRemoveAbilityBJ takes integer abilityId, unit whichUnit returns boolean
    return UnitRemoveAbility(whichUnit, abilityId)
endfunction
]]>
    </Function>

    <Function Name="UnitAddAbilityBJ" ReturnType="boolean" ArgumentList="integer abilityId, unit whichUnit">
      <![CDATA[function UnitAddAbilityBJ takes integer abilityId, unit whichUnit returns boolean
    return UnitAddAbility(whichUnit, abilityId)
endfunction
]]>
    </Function>

    <Function Name="SetUnitExplodedBJ" ReturnType="nothing" ArgumentList="unit whichUnit, boolean exploded">
      <![CDATA[function SetUnitExplodedBJ takes unit whichUnit, boolean exploded returns nothing
    call SetUnitExploded(whichUnit, exploded)
endfunction
]]>
    </Function>

    <Function Name="ExplodeUnitBJ" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function ExplodeUnitBJ takes unit whichUnit returns nothing
    call SetUnitExploded(whichUnit, true)
    call KillUnit(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="GetTransportUnitBJ" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[function GetTransportUnitBJ takes nothing returns unit
    return GetTransportUnit()
endfunction
]]>
    </Function>

    <Function Name="GetLoadedUnitBJ" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[function GetLoadedUnitBJ takes nothing returns unit
    return GetLoadedUnit()
endfunction
]]>
    </Function>

    <Function Name="IsUnitInTransportBJ" ReturnType="boolean" ArgumentList="unit whichUnit, unit whichTransport">
      <![CDATA[function IsUnitInTransportBJ takes unit whichUnit, unit whichTransport returns boolean
    return IsUnitInTransport(whichUnit, whichTransport)
endfunction
]]>
    </Function>

    <Function Name="IsUnitLoadedBJ" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function IsUnitLoadedBJ takes unit whichUnit returns boolean
    return IsUnitLoaded(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="IsUnitIllusionBJ" ReturnType="boolean" ArgumentList="unit whichUnit">
      <![CDATA[function IsUnitIllusionBJ takes unit whichUnit returns boolean
    return IsUnitIllusion(whichUnit)
endfunction
]]>
    </Function>

    <Function Name="ReplaceUnitBJ" ReturnType="unit" ArgumentList="unit whichUnit, integer newUnitId, integer unitStateMethod">
      <![CDATA[function ReplaceUnitBJ takes unit whichUnit, integer newUnitId, integer unitStateMethod returns unit
    local unit    oldUnit = whichUnit
    local unit    newUnit
    local boolean wasHidden
    local integer index
    local item    indexItem
    local real    oldRatio

    // If we have bogus data, don't attempt the replace.
    if (oldUnit == null) then
        set bj_lastReplacedUnit = oldUnit
        return oldUnit
    endif

    // Hide the original unit.
    set wasHidden = IsUnitHidden(oldUnit)
    call ShowUnit(oldUnit, false)

    // Create the replacement unit.
    if (newUnitId == 'ugol') then
        set newUnit = CreateBlightedGoldmine(GetOwningPlayer(oldUnit), GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    else
        set newUnit = CreateUnit(GetOwningPlayer(oldUnit), newUnitId, GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    endif

    // Set the unit's life and mana according to the requested method.
    if (unitStateMethod == bj_UNIT_STATE_METHOD_RELATIVE) then
        // Set the replacement's current/max life ratio to that of the old unit.
        // If both units have mana, do the same for mana.
        if (GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_LIFE) / GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE)
            call SetUnitState(newUnit, UNIT_STATE_LIFE, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        endif

        if (GetUnitState(oldUnit, UNIT_STATE_MAX_MANA) > 0) and (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_MANA) / GetUnitState(oldUnit, UNIT_STATE_MAX_MANA)
            call SetUnitState(newUnit, UNIT_STATE_MANA, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_ABSOLUTE) then
        // Set the replacement's current life to that of the old unit.
        // If the new unit has mana, do the same for mana.
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(oldUnit, UNIT_STATE_LIFE))
        if (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(oldUnit, UNIT_STATE_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_DEFAULTS) then
        // The newly created unit should already have default life and mana.
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_MAXIMUM) then
        // Use max life and mana.
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
    else
        // Unrecognized unit state method - ignore the request.
    endif

    // Mirror properties of the old unit onto the new unit.
    //call PauseUnit(newUnit, IsUnitPaused(oldUnit))
    call SetResourceAmount(newUnit, GetResourceAmount(oldUnit))

    // If both the old and new units are heroes, handle their hero info.
    if (IsUnitType(oldUnit, UNIT_TYPE_HERO) and IsUnitType(newUnit, UNIT_TYPE_HERO)) then
        call SetHeroXP(newUnit, GetHeroXP(oldUnit), false)

        set index = 0
        loop
            set indexItem = UnitItemInSlot(oldUnit, index)
            if (indexItem != null) then
                call UnitRemoveItem(oldUnit, indexItem)
                call UnitAddItem(newUnit, indexItem)
            endif

            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY
        endloop
    endif

    // Remove or kill the original unit.  It is sometimes unsafe to remove
    // hidden units, so kill the original unit if it was previously hidden.
    if wasHidden then
        call KillUnit(oldUnit)
        call RemoveUnit(oldUnit)
    else
        call RemoveUnit(oldUnit)
    endif

    set bj_lastReplacedUnit = newUnit
    return newUnit
endfunction
]]>
    </Function>

    <Function Name="GetLastReplacedUnitBJ" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[function GetLastReplacedUnitBJ takes nothing returns unit
    return bj_lastReplacedUnit
endfunction
]]>
    </Function>

    <Function Name="SetUnitPositionLocFacingBJ" ReturnType="nothing" ArgumentList="unit whichUnit, location loc, real facing">
      <![CDATA[function SetUnitPositionLocFacingBJ takes unit whichUnit, location loc, real facing returns nothing
    call SetUnitPositionLoc(whichUnit, loc)
    call SetUnitFacing(whichUnit, facing)
endfunction
]]>
    </Function>

    <Function Name="SetUnitPositionLocFacingLocBJ" ReturnType="nothing" ArgumentList="unit whichUnit, location loc, location lookAt">
      <![CDATA[function SetUnitPositionLocFacingLocBJ takes unit whichUnit, location loc, location lookAt returns nothing
    call SetUnitPositionLoc(whichUnit, loc)
    call SetUnitFacing(whichUnit, AngleBetweenPoints(loc, lookAt))
endfunction
]]>
    </Function>

    <Function Name="AddItemToStockBJ" ReturnType="nothing" ArgumentList="integer itemId, unit whichUnit, integer currentStock, integer stockMax">
      <![CDATA[function AddItemToStockBJ takes integer itemId, unit whichUnit, integer currentStock, integer stockMax returns nothing
    call AddItemToStock(whichUnit, itemId, currentStock, stockMax)
endfunction
]]>
    </Function>

    <Function Name="AddUnitToStockBJ" ReturnType="nothing" ArgumentList="integer unitId, unit whichUnit, integer currentStock, integer stockMax">
      <![CDATA[function AddUnitToStockBJ takes integer unitId, unit whichUnit, integer currentStock, integer stockMax returns nothing
    call AddUnitToStock(whichUnit, unitId, currentStock, stockMax)
endfunction
]]>
    </Function>

    <Function Name="RemoveItemFromStockBJ" ReturnType="nothing" ArgumentList="integer itemId, unit whichUnit">
      <![CDATA[function RemoveItemFromStockBJ takes integer itemId, unit whichUnit returns nothing
    call RemoveItemFromStock(whichUnit, itemId)
endfunction
]]>
    </Function>

    <Function Name="RemoveUnitFromStockBJ" ReturnType="nothing" ArgumentList="integer unitId, unit whichUnit">
      <![CDATA[function RemoveUnitFromStockBJ takes integer unitId, unit whichUnit returns nothing
    call RemoveUnitFromStock(whichUnit, unitId)
endfunction
]]>
    </Function>

    <Function Name="SetUnitUseFoodBJ" ReturnType="nothing" ArgumentList="boolean enable, unit whichUnit">
      <![CDATA[function SetUnitUseFoodBJ takes boolean enable, unit whichUnit returns nothing
    call SetUnitUseFood(whichUnit, enable)
endfunction
]]>
    </Function>

    <Function Name="CreateDestructableLoc" ReturnType="destructable" ArgumentList="integer objectid, location loc, real facing, real scale, integer variation">
      <![CDATA[function CreateDestructableLoc takes integer objectid, location loc, real facing, real scale, integer variation returns destructable
    set bj_lastCreatedDestructable = CreateDestructable(objectid, GetLocationX(loc), GetLocationY(loc), facing, scale, variation)
    return bj_lastCreatedDestructable
endfunction
]]>
    </Function>

    <Function Name="CreateDeadDestructableLocBJ" ReturnType="destructable" ArgumentList="integer objectid, location loc, real facing, real scale, integer variation">
      <![CDATA[function CreateDeadDestructableLocBJ takes integer objectid, location loc, real facing, real scale, integer variation returns destructable
    set bj_lastCreatedDestructable = CreateDeadDestructable(objectid, GetLocationX(loc), GetLocationY(loc), facing, scale, variation)
    return bj_lastCreatedDestructable
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedDestructable" ReturnType="destructable" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedDestructable takes nothing returns destructable
    return bj_lastCreatedDestructable
endfunction
]]>
    </Function>

    <Function Name="ShowDestructableBJ" ReturnType="nothing" ArgumentList="boolean flag, destructable d">
      <![CDATA[function ShowDestructableBJ takes boolean flag, destructable d returns nothing
    call ShowDestructable(d, flag)
endfunction
]]>
    </Function>

    <Function Name="SetDestructableInvulnerableBJ" ReturnType="nothing" ArgumentList="destructable d, boolean flag">
      <![CDATA[function SetDestructableInvulnerableBJ takes destructable d, boolean flag returns nothing
    call SetDestructableInvulnerable(d, flag)
endfunction
]]>
    </Function>

    <Function Name="IsDestructableInvulnerableBJ" ReturnType="boolean" ArgumentList="destructable d">
      <![CDATA[function IsDestructableInvulnerableBJ takes destructable d returns boolean
    return IsDestructableInvulnerable(d)
endfunction
]]>
    </Function>

    <Function Name="GetDestructableLoc" ReturnType="location" ArgumentList="destructable whichDestructable">
      <![CDATA[function GetDestructableLoc takes destructable whichDestructable returns location
    return Location(GetDestructableX(whichDestructable), GetDestructableY(whichDestructable))
endfunction
]]>
    </Function>

    <Function Name="EnumDestructablesInRectAll" ReturnType="nothing" ArgumentList="rect r, code actionFunc">
      <![CDATA[function EnumDestructablesInRectAll takes rect r, code actionFunc returns nothing
    call EnumDestructablesInRect(r, null, actionFunc)
endfunction
]]>
    </Function>

    <Function Name="EnumDestructablesInCircleBJFilter" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function EnumDestructablesInCircleBJFilter takes nothing returns boolean
    local location destLoc = GetDestructableLoc(GetFilterDestructable())
    local boolean result

    set result = DistanceBetweenPoints(destLoc, bj_enumDestructableCenter) <= bj_enumDestructableRadius
    call RemoveLocation(destLoc)
    return result
endfunction
]]>
    </Function>

    <Function Name="IsDestructableDeadBJ" ReturnType="boolean" ArgumentList="destructable d">
      <![CDATA[function IsDestructableDeadBJ takes destructable d returns boolean
    return GetDestructableLife(d) <= 0
endfunction
]]>
    </Function>

    <Function Name="IsDestructableAliveBJ" ReturnType="boolean" ArgumentList="destructable d">
      <![CDATA[function IsDestructableAliveBJ takes destructable d returns boolean
    return not IsDestructableDeadBJ(d)
endfunction
]]>
    </Function>

    <Function Name="RandomDestructableInRectBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function RandomDestructableInRectBJEnum takes nothing returns nothing
    set bj_destRandomConsidered = bj_destRandomConsidered + 1
    if (GetRandomInt(1,bj_destRandomConsidered) == 1) then
        set bj_destRandomCurrentPick = GetEnumDestructable()
    endif
endfunction
]]>
    </Function>

    <Function Name="RandomDestructableInRectBJ" ReturnType="destructable" ArgumentList="rect r, boolexpr filter">
      <![CDATA[function RandomDestructableInRectBJ takes rect r, boolexpr filter returns destructable
    set bj_destRandomConsidered = 0
    set bj_destRandomCurrentPick = null
    call EnumDestructablesInRect(r, filter, function RandomDestructableInRectBJEnum)
    call DestroyBoolExpr(filter)
    return bj_destRandomCurrentPick
endfunction
]]>
    </Function>

    <Function Name="RandomDestructableInRectSimpleBJ" ReturnType="destructable" ArgumentList="rect r">
      <![CDATA[function RandomDestructableInRectSimpleBJ takes rect r returns destructable
    return RandomDestructableInRectBJ(r, null)
endfunction
]]>
    </Function>

    <Function Name="EnumDestructablesInCircleBJ" ReturnType="nothing" ArgumentList="real radius, location loc, code actionFunc">
      <![CDATA[function EnumDestructablesInCircleBJ takes real radius, location loc, code actionFunc returns nothing
    local rect r

    if (radius >= 0) then
        set bj_enumDestructableCenter = loc
        set bj_enumDestructableRadius = radius
        set r = GetRectFromCircleBJ(loc, radius)
        call EnumDestructablesInRect(r, filterEnumDestructablesInCircleBJ, actionFunc)
        call RemoveRect(r)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetDestructableLifePercentBJ" ReturnType="nothing" ArgumentList="destructable d, real percent">
      <![CDATA[function SetDestructableLifePercentBJ takes destructable d, real percent returns nothing
    call SetDestructableLife(d, GetDestructableMaxLife(d) * percent * 0.01)
endfunction
]]>
    </Function>

    <Function Name="SetDestructableMaxLifeBJ" ReturnType="nothing" ArgumentList="destructable d, real max">
      <![CDATA[function SetDestructableMaxLifeBJ takes destructable d, real max returns nothing
    call SetDestructableMaxLife(d, max)
endfunction
]]>
    </Function>

    <Function Name="ModifyGateBJ" ReturnType="nothing" ArgumentList="integer gateOperation, destructable d">
      <![CDATA[function ModifyGateBJ takes integer gateOperation, destructable d returns nothing
    if (gateOperation == bj_GATEOPERATION_CLOSE) then
        if (GetDestructableLife(d) <= 0) then
            call DestructableRestoreLife(d, GetDestructableMaxLife(d), true)
        endif
        call SetDestructableAnimation(d, "stand")
    elseif (gateOperation == bj_GATEOPERATION_OPEN) then
        if (GetDestructableLife(d) > 0) then
            call KillDestructable(d)
        endif
        call SetDestructableAnimation(d, "death alternate")
    elseif (gateOperation == bj_GATEOPERATION_DESTROY) then
        if (GetDestructableLife(d) > 0) then
            call KillDestructable(d)
        endif
        call SetDestructableAnimation(d, "death")
    else
        // Unrecognized gate state - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="GetElevatorHeight" ReturnType="integer" ArgumentList="destructable d">
      <![CDATA[function GetElevatorHeight takes destructable d returns integer
    local integer height

    set height = 1 + R2I(GetDestructableOccluderHeight(d) / bj_CLIFFHEIGHT)
    if (height < 1) or (height > 3) then
        set height = 1
    endif
    return height
endfunction
]]>
    </Function>

    <Function Name="ChangeElevatorHeight" ReturnType="nothing" ArgumentList="destructable d, integer newHeight">
      <![CDATA[function ChangeElevatorHeight takes destructable d, integer newHeight returns nothing
    local integer oldHeight

    // Cap the new height within the supported range.
    set newHeight = IMaxBJ(1, newHeight)
    set newHeight = IMinBJ(3, newHeight)

    // Find out what height the elevator is already at.
    set oldHeight = GetElevatorHeight(d)

    // Set the elevator's occlusion height.
    call SetDestructableOccluderHeight(d, bj_CLIFFHEIGHT*(newHeight-1))

    if (newHeight == 1) then
        if (oldHeight == 2) then
            call SetDestructableAnimation(d, "birth")
            call QueueDestructableAnimation(d, "stand")
        elseif (oldHeight == 3) then
            call SetDestructableAnimation(d, "birth third")
            call QueueDestructableAnimation(d, "stand")
        else
            // Unrecognized old height - snap to new height.
            call SetDestructableAnimation(d, "stand")
        endif
    elseif (newHeight == 2) then
        if (oldHeight == 1) then
            call SetDestructableAnimation(d, "death")
            call QueueDestructableAnimation(d, "stand second")
        elseif (oldHeight == 3) then
            call SetDestructableAnimation(d, "birth second")
            call QueueDestructableAnimation(d, "stand second")
        else
            // Unrecognized old height - snap to new height.
            call SetDestructableAnimation(d, "stand second")
        endif
    elseif (newHeight == 3) then
        if (oldHeight == 1) then
            call SetDestructableAnimation(d, "death third")
            call QueueDestructableAnimation(d, "stand third")
        elseif (oldHeight == 2) then
            call SetDestructableAnimation(d, "death second")
            call QueueDestructableAnimation(d, "stand third")
        else
            // Unrecognized old height - snap to new height.
            call SetDestructableAnimation(d, "stand third")
        endif
    else
        // Unrecognized new height - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="NudgeUnitsInRectEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function NudgeUnitsInRectEnum takes nothing returns nothing
    local unit nudgee = GetEnumUnit()

    call SetUnitPosition(nudgee, GetUnitX(nudgee), GetUnitY(nudgee))
endfunction
]]>
    </Function>

    <Function Name="NudgeItemsInRectEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function NudgeItemsInRectEnum takes nothing returns nothing
    local item nudgee = GetEnumItem()

    call SetItemPosition(nudgee, GetItemX(nudgee), GetItemY(nudgee))
endfunction
]]>
    </Function>

    <Function Name="NudgeObjectsInRect" ReturnType="nothing" ArgumentList="rect nudgeArea">
      <![CDATA[function NudgeObjectsInRect takes rect nudgeArea returns nothing
    local group        g

    set g = CreateGroup()
    call GroupEnumUnitsInRect(g, nudgeArea, null)
    call ForGroup(g, function NudgeUnitsInRectEnum)
    call DestroyGroup(g)

    call EnumItemsInRect(nudgeArea, null, function NudgeItemsInRectEnum)
endfunction
]]>
    </Function>

    <Function Name="NearbyElevatorExistsEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function NearbyElevatorExistsEnum takes nothing returns nothing
    local destructable d     = GetEnumDestructable()
    local integer      dType = GetDestructableTypeId(d)

    if (dType == bj_ELEVATOR_CODE01) or (dType == bj_ELEVATOR_CODE02) then
        set bj_elevatorNeighbor = d
    endif
endfunction
]]>
    </Function>

    <Function Name="NearbyElevatorExists" ReturnType="boolean" ArgumentList="real x, real y">
      <![CDATA[function NearbyElevatorExists takes real x, real y returns boolean
    local real findThreshold = 32
    local rect r

    // If another elevator is overlapping this one, ignore the wall.
    set r = Rect(x - findThreshold, y - findThreshold, x + findThreshold, y + findThreshold)
    set bj_elevatorNeighbor = null
    call EnumDestructablesInRect(r, null, function NearbyElevatorExistsEnum)
    call RemoveRect(r)

    return bj_elevatorNeighbor != null
endfunction
]]>
    </Function>

    <Function Name="FindElevatorWallBlockerEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function FindElevatorWallBlockerEnum takes nothing returns nothing
    set bj_elevatorWallBlocker = GetEnumDestructable()
endfunction
]]>
    </Function>

    <Function Name="ChangeElevatorWallBlocker" ReturnType="nothing" ArgumentList="real x, real y, real facing, boolean open">
      <![CDATA[function ChangeElevatorWallBlocker takes real x, real y, real facing, boolean open returns nothing
    local destructable blocker = null
    local real         findThreshold = 32
    local real         nudgeLength   = 4.25 * bj_CELLWIDTH
    local real         nudgeWidth    = 1.25 * bj_CELLWIDTH
    local rect         r

    // Search for the pathing blocker within the general area.
    set r = Rect(x - findThreshold, y - findThreshold, x + findThreshold, y + findThreshold)
    set bj_elevatorWallBlocker = null
    call EnumDestructablesInRect(r, null, function FindElevatorWallBlockerEnum)
    call RemoveRect(r)
    set blocker = bj_elevatorWallBlocker

    // Ensure that the blocker exists.
    if (blocker == null) then
        set blocker = CreateDeadDestructable(bj_ELEVATOR_BLOCKER_CODE, x, y, facing, 1, 0)
    elseif (GetDestructableTypeId(blocker) != bj_ELEVATOR_BLOCKER_CODE) then
        // If a different destructible exists in the blocker's spot, ignore
        // the request.  (Two destructibles cannot occupy the same location
        // on the map, so we cannot create an elevator blocker here.)
        return
    endif

    if (open) then
        // Ensure that the blocker is dead.
        if (GetDestructableLife(blocker) > 0) then
            call KillDestructable(blocker)
        endif
    else
        // Ensure that the blocker is alive.
        if (GetDestructableLife(blocker) <= 0) then
            call DestructableRestoreLife(blocker, GetDestructableMaxLife(blocker), false)
        endif

        // Nudge any objects standing in the blocker's way.
        if (facing == 0) then
            set r = Rect(x - nudgeWidth/2, y - nudgeLength/2, x + nudgeWidth/2, y + nudgeLength/2)
            call NudgeObjectsInRect(r)
            call RemoveRect(r)
        elseif (facing == 90) then
            set r = Rect(x - nudgeLength/2, y - nudgeWidth/2, x + nudgeLength/2, y + nudgeWidth/2)
            call NudgeObjectsInRect(r)
            call RemoveRect(r)
        else
            // Unrecognized blocker angle - don't nudge anything.
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="ChangeElevatorWalls" ReturnType="nothing" ArgumentList="boolean open, integer walls, destructable d">
      <![CDATA[function ChangeElevatorWalls takes boolean open, integer walls, destructable d returns nothing
    local real x = GetDestructableX(d)
    local real y = GetDestructableY(d)
    local real distToBlocker = 192
    local real distToNeighbor = 256

    if (walls == bj_ELEVATOR_WALL_TYPE_ALL) or (walls == bj_ELEVATOR_WALL_TYPE_EAST) then
        if (not NearbyElevatorExists(x + distToNeighbor, y)) then
            call ChangeElevatorWallBlocker(x + distToBlocker, y, 0, open)
        endif
    endif

    if (walls == bj_ELEVATOR_WALL_TYPE_ALL) or (walls == bj_ELEVATOR_WALL_TYPE_NORTH) then
        if (not NearbyElevatorExists(x, y + distToNeighbor)) then
            call ChangeElevatorWallBlocker(x, y + distToBlocker, 90, open)
        endif
    endif

    if (walls == bj_ELEVATOR_WALL_TYPE_ALL) or (walls == bj_ELEVATOR_WALL_TYPE_SOUTH) then
        if (not NearbyElevatorExists(x, y - distToNeighbor)) then
            call ChangeElevatorWallBlocker(x, y - distToBlocker, 90, open)
        endif
    endif

    if (walls == bj_ELEVATOR_WALL_TYPE_ALL) or (walls == bj_ELEVATOR_WALL_TYPE_WEST) then
        if (not NearbyElevatorExists(x - distToNeighbor, y)) then
            call ChangeElevatorWallBlocker(x - distToBlocker, y, 0, open)
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="WaygateActivateBJ" ReturnType="nothing" ArgumentList="boolean activate, unit waygate">
      <![CDATA[function WaygateActivateBJ takes boolean activate, unit waygate returns nothing
    call WaygateActivate(waygate, activate)
endfunction
]]>
    </Function>

    <Function Name="WaygateIsActiveBJ" ReturnType="boolean" ArgumentList="unit waygate">
      <![CDATA[function WaygateIsActiveBJ takes unit waygate returns boolean
    return WaygateIsActive(waygate)
endfunction
]]>
    </Function>

    <Function Name="WaygateSetDestinationLocBJ" ReturnType="nothing" ArgumentList="unit waygate, location loc">
      <![CDATA[function WaygateSetDestinationLocBJ takes unit waygate, location loc returns nothing
    call WaygateSetDestination(waygate, GetLocationX(loc), GetLocationY(loc))
endfunction
]]>
    </Function>

    <Function Name="WaygateGetDestinationLocBJ" ReturnType="location" ArgumentList="unit waygate">
      <![CDATA[function WaygateGetDestinationLocBJ takes unit waygate returns location
    return Location(WaygateGetDestinationX(waygate), WaygateGetDestinationY(waygate))
endfunction
]]>
    </Function>

    <Function Name="UnitSetUsesAltIconBJ" ReturnType="nothing" ArgumentList="boolean flag, unit whichUnit">
      <![CDATA[function UnitSetUsesAltIconBJ takes boolean flag, unit whichUnit returns nothing
    call UnitSetUsesAltIcon(whichUnit, flag)
endfunction
]]>
    </Function>

    <Function Name="ForceUIKeyBJ" ReturnType="nothing" ArgumentList="player whichPlayer, string key">
      <![CDATA[function ForceUIKeyBJ takes player whichPlayer, string key returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ForceUIKey(key)
    endif
endfunction
]]>
    </Function>

    <Function Name="ForceUICancelBJ" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function ForceUICancelBJ takes player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ForceUICancel()
    endif
endfunction
]]>
    </Function>

    <Function Name="ForGroupBJ" ReturnType="nothing" ArgumentList="group whichGroup, code callback">
      <![CDATA[function ForGroupBJ takes group whichGroup, code callback returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    call ForGroup(whichGroup, callback)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
endfunction
]]>
    </Function>

    <Function Name="GroupAddUnitSimple" ReturnType="nothing" ArgumentList="unit whichUnit, group whichGroup">
      <![CDATA[function GroupAddUnitSimple takes unit whichUnit, group whichGroup returns nothing
    call GroupAddUnit(whichGroup, whichUnit)
endfunction
]]>
    </Function>

    <Function Name="GroupRemoveUnitSimple" ReturnType="nothing" ArgumentList="unit whichUnit, group whichGroup">
      <![CDATA[function GroupRemoveUnitSimple takes unit whichUnit, group whichGroup returns nothing
    call GroupRemoveUnit(whichGroup, whichUnit)
endfunction
]]>
    </Function>

    <Function Name="GroupAddGroupEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function GroupAddGroupEnum takes nothing returns nothing
    call GroupAddUnit(bj_groupAddGroupDest, GetEnumUnit())
endfunction
]]>
    </Function>

    <Function Name="GroupAddGroup" ReturnType="nothing" ArgumentList="group sourceGroup, group destGroup">
      <![CDATA[function GroupAddGroup takes group sourceGroup, group destGroup returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupAddGroupDest = destGroup
    call ForGroup(sourceGroup, function GroupAddGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(sourceGroup)
    endif
endfunction
]]>
    </Function>

    <Function Name="GroupRemoveGroupEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function GroupRemoveGroupEnum takes nothing returns nothing
    call GroupRemoveUnit(bj_groupRemoveGroupDest, GetEnumUnit())
endfunction
]]>
    </Function>

    <Function Name="GroupRemoveGroup" ReturnType="nothing" ArgumentList="group sourceGroup, group destGroup">
      <![CDATA[function GroupRemoveGroup takes group sourceGroup, group destGroup returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupRemoveGroupDest = destGroup
    call ForGroup(sourceGroup, function GroupRemoveGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(sourceGroup)
    endif
endfunction
]]>
    </Function>

    <Function Name="ForceAddPlayerSimple" ReturnType="nothing" ArgumentList="player whichPlayer, force whichForce">
      <![CDATA[function ForceAddPlayerSimple takes player whichPlayer, force whichForce returns nothing
    call ForceAddPlayer(whichForce, whichPlayer)
endfunction
]]>
    </Function>

    <Function Name="ForceRemovePlayerSimple" ReturnType="nothing" ArgumentList="player whichPlayer, force whichForce">
      <![CDATA[function ForceRemovePlayerSimple takes player whichPlayer, force whichForce returns nothing
    call ForceRemovePlayer(whichForce, whichPlayer)
endfunction
]]>
    </Function>

    <Function Name="GroupPickRandomUnitEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function GroupPickRandomUnitEnum takes nothing returns nothing
    set bj_groupRandomConsidered = bj_groupRandomConsidered + 1
    if (GetRandomInt(1,bj_groupRandomConsidered) == 1) then
        set bj_groupRandomCurrentPick = GetEnumUnit()
    endif
endfunction
]]>
    </Function>

    <Function Name="GroupPickRandomUnit" ReturnType="unit" ArgumentList="group whichGroup">
      <![CDATA[function GroupPickRandomUnit takes group whichGroup returns unit
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupRandomConsidered = 0
    set bj_groupRandomCurrentPick = null
    call ForGroup(whichGroup, function GroupPickRandomUnitEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
    return bj_groupRandomCurrentPick
endfunction
]]>
    </Function>

    <Function Name="ForcePickRandomPlayerEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function ForcePickRandomPlayerEnum takes nothing returns nothing
    set bj_forceRandomConsidered = bj_forceRandomConsidered + 1
    if (GetRandomInt(1,bj_forceRandomConsidered) == 1) then
        set bj_forceRandomCurrentPick = GetEnumPlayer()
    endif
endfunction
]]>
    </Function>

    <Function Name="ForcePickRandomPlayer" ReturnType="player" ArgumentList="force whichForce">
      <![CDATA[function ForcePickRandomPlayer takes force whichForce returns player
    set bj_forceRandomConsidered = 0
    set bj_forceRandomCurrentPick = null
    call ForForce(whichForce, function ForcePickRandomPlayerEnum)
    return bj_forceRandomCurrentPick
endfunction
]]>
    </Function>

    <Function Name="EnumUnitsSelected" ReturnType="nothing" ArgumentList="player whichPlayer, boolexpr enumFilter, code enumAction">
      <![CDATA[function EnumUnitsSelected takes player whichPlayer, boolexpr enumFilter, code enumAction returns nothing
    local group g = CreateGroup()
    call SyncSelections()
    call GroupEnumUnitsSelected(g, whichPlayer, enumFilter)
    call DestroyBoolExpr(enumFilter)
    call ForGroup(g, enumAction)
    call DestroyGroup(g)
endfunction
]]>
    </Function>

    <Function Name="GetUnitsInRectMatching" ReturnType="group" ArgumentList="rect r, boolexpr filter">
      <![CDATA[function GetUnitsInRectMatching takes rect r, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, r, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction
]]>
    </Function>

    <Function Name="GetUnitsInRectAll" ReturnType="group" ArgumentList="rect r">
      <![CDATA[function GetUnitsInRectAll takes rect r returns group
    return GetUnitsInRectMatching(r, null)
endfunction
]]>
    </Function>

    <Function Name="GetUnitsInRectOfPlayerFilter" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function GetUnitsInRectOfPlayerFilter takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == bj_groupEnumOwningPlayer
endfunction
]]>
    </Function>

    <Function Name="GetUnitsInRectOfPlayer" ReturnType="group" ArgumentList="rect r, player whichPlayer">
      <![CDATA[function GetUnitsInRectOfPlayer takes rect r, player whichPlayer returns group
    local group g = CreateGroup()
    set bj_groupEnumOwningPlayer = whichPlayer
    call GroupEnumUnitsInRect(g, r, filterGetUnitsInRectOfPlayer)
    return g
endfunction
]]>
    </Function>

    <Function Name="GetUnitsInRangeOfLocMatching" ReturnType="group" ArgumentList="real radius, location whichLocation, boolexpr filter">
      <![CDATA[function GetUnitsInRangeOfLocMatching takes real radius, location whichLocation, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(g, whichLocation, radius, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction
]]>
    </Function>

    <Function Name="GetUnitsInRangeOfLocAll" ReturnType="group" ArgumentList="real radius, location whichLocation">
      <![CDATA[function GetUnitsInRangeOfLocAll takes real radius, location whichLocation returns group
    return GetUnitsInRangeOfLocMatching(radius, whichLocation, null)
endfunction
]]>
    </Function>

    <Function Name="GetUnitsOfTypeIdAllFilter" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function GetUnitsOfTypeIdAllFilter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == bj_groupEnumTypeId
endfunction
]]>
    </Function>

    <Function Name="GetUnitsOfTypeIdAll" ReturnType="group" ArgumentList="integer unitid">
      <![CDATA[function GetUnitsOfTypeIdAll takes integer unitid returns group
    local group   result = CreateGroup()
    local group   g      = CreateGroup()
    local integer index

    set index = 0
    loop
        set bj_groupEnumTypeId = unitid
        call GroupClear(g)
        call GroupEnumUnitsOfPlayer(g, Player(index), filterGetUnitsOfTypeIdAll)
        call GroupAddGroup(g, result)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call DestroyGroup(g)

    return result
endfunction
]]>
    </Function>

    <Function Name="GetUnitsOfPlayerMatching" ReturnType="group" ArgumentList="player whichPlayer, boolexpr filter">
      <![CDATA[function GetUnitsOfPlayerMatching takes player whichPlayer, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction
]]>
    </Function>

    <Function Name="GetUnitsOfPlayerAll" ReturnType="group" ArgumentList="player whichPlayer">
      <![CDATA[function GetUnitsOfPlayerAll takes player whichPlayer returns group
    return GetUnitsOfPlayerMatching(whichPlayer, null)
endfunction
]]>
    </Function>

    <Function Name="GetUnitsOfPlayerAndTypeIdFilter" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function GetUnitsOfPlayerAndTypeIdFilter takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == bj_groupEnumTypeId
endfunction
]]>
    </Function>

    <Function Name="GetUnitsOfPlayerAndTypeId" ReturnType="group" ArgumentList="player whichPlayer, integer unitid">
      <![CDATA[function GetUnitsOfPlayerAndTypeId takes player whichPlayer, integer unitid returns group
    local group g = CreateGroup()
    set bj_groupEnumTypeId = unitid
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterGetUnitsOfPlayerAndTypeId)
    return g
endfunction
]]>
    </Function>

    <Function Name="GetUnitsSelectedAll" ReturnType="group" ArgumentList="player whichPlayer">
      <![CDATA[function GetUnitsSelectedAll takes player whichPlayer returns group
    local group g = CreateGroup()
    call SyncSelections()
    call GroupEnumUnitsSelected(g, whichPlayer, null)
    return g
endfunction
]]>
    </Function>

    <Function Name="GetForceOfPlayer" ReturnType="force" ArgumentList="player whichPlayer">
      <![CDATA[function GetForceOfPlayer takes player whichPlayer returns force
    local force f = CreateForce()
    call ForceAddPlayer(f, whichPlayer)
    return f
endfunction
]]>
    </Function>

    <Function Name="GetPlayersAll" ReturnType="force" ArgumentList="nothing">
      <![CDATA[function GetPlayersAll takes nothing returns force
    return bj_FORCE_ALL_PLAYERS
endfunction
]]>
    </Function>

    <Function Name="GetPlayersByMapControl" ReturnType="force" ArgumentList="mapcontrol whichControl">
      <![CDATA[function GetPlayersByMapControl takes mapcontrol whichControl returns force
    local force f = CreateForce()
    local integer playerIndex
    local player  indexPlayer

    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if GetPlayerController(indexPlayer) == whichControl then
            call ForceAddPlayer(f, indexPlayer)
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
    endloop

    return f
endfunction
]]>
    </Function>

    <Function Name="GetPlayersAllies" ReturnType="force" ArgumentList="player whichPlayer">
      <![CDATA[function GetPlayersAllies takes player whichPlayer returns force
    local force f = CreateForce()
    call ForceEnumAllies(f, whichPlayer, null)
    return f
endfunction
]]>
    </Function>

    <Function Name="GetPlayersEnemies" ReturnType="force" ArgumentList="player whichPlayer">
      <![CDATA[function GetPlayersEnemies takes player whichPlayer returns force
    local force f = CreateForce()
    call ForceEnumEnemies(f, whichPlayer, null)
    return f
endfunction
]]>
    </Function>

    <Function Name="GetPlayersMatching" ReturnType="force" ArgumentList="boolexpr filter">
      <![CDATA[function GetPlayersMatching takes boolexpr filter returns force
    local force f = CreateForce()
    call ForceEnumPlayers(f, filter)
    call DestroyBoolExpr(filter)
    return f
endfunction
]]>
    </Function>

    <Function Name="CountUnitsInGroupEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CountUnitsInGroupEnum takes nothing returns nothing
    set bj_groupCountUnits = bj_groupCountUnits + 1
endfunction
]]>
    </Function>

    <Function Name="CountUnitsInGroup" ReturnType="integer" ArgumentList="group g">
      <![CDATA[function CountUnitsInGroup takes group g returns integer
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupCountUnits = 0
    call ForGroup(g, function CountUnitsInGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_groupCountUnits
endfunction
]]>
    </Function>

    <Function Name="CountPlayersInForceEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CountPlayersInForceEnum takes nothing returns nothing
    set bj_forceCountPlayers = bj_forceCountPlayers + 1
endfunction
]]>
    </Function>

    <Function Name="CountPlayersInForceBJ" ReturnType="integer" ArgumentList="force f">
      <![CDATA[function CountPlayersInForceBJ takes force f returns integer
    set bj_forceCountPlayers = 0
    call ForForce(f, function CountPlayersInForceEnum)
    return bj_forceCountPlayers
endfunction
]]>
    </Function>

    <Function Name="GetRandomSubGroupEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function GetRandomSubGroupEnum takes nothing returns nothing
    if (bj_randomSubGroupWant > 0) then
        if (bj_randomSubGroupWant >= bj_randomSubGroupTotal) or (GetRandomReal(0,1) < bj_randomSubGroupChance) then
            // We either need every remaining unit, or the unit passed its chance check.
            call GroupAddUnit(bj_randomSubGroupGroup, GetEnumUnit())
            set bj_randomSubGroupWant = bj_randomSubGroupWant - 1
        endif
    endif
    set bj_randomSubGroupTotal = bj_randomSubGroupTotal - 1
endfunction
]]>
    </Function>

    <Function Name="GetRandomSubGroup" ReturnType="group" ArgumentList="integer count, group sourceGroup">
      <![CDATA[function GetRandomSubGroup takes integer count, group sourceGroup returns group
    local group g = CreateGroup()

    set bj_randomSubGroupGroup = g
    set bj_randomSubGroupWant  = count
    set bj_randomSubGroupTotal = CountUnitsInGroup(sourceGroup)

    if (bj_randomSubGroupWant <= 0 or bj_randomSubGroupTotal <= 0) then
        return g
    endif

    set bj_randomSubGroupChance = I2R(bj_randomSubGroupWant) / I2R(bj_randomSubGroupTotal)
    call ForGroup(sourceGroup, function GetRandomSubGroupEnum)
    return g
endfunction
]]>
    </Function>

    <Function Name="LivingPlayerUnitsOfTypeIdFilter" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function LivingPlayerUnitsOfTypeIdFilter takes nothing returns boolean
    local unit filterUnit = GetFilterUnit()
    return IsUnitAliveBJ(filterUnit) and GetUnitTypeId(filterUnit) == bj_livingPlayerUnitsTypeId
endfunction
]]>
    </Function>

    <Function Name="CountLivingPlayerUnitsOfTypeId" ReturnType="integer" ArgumentList="integer unitId, player whichPlayer">
      <![CDATA[function CountLivingPlayerUnitsOfTypeId takes integer unitId, player whichPlayer returns integer
    local group g
    local integer matchedCount

    set g = CreateGroup()
    set bj_livingPlayerUnitsTypeId = unitId
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filterLivingPlayerUnitsOfTypeId)
    set matchedCount = CountUnitsInGroup(g)
    call DestroyGroup(g)

    return matchedCount
endfunction
]]>
    </Function>

    <Function Name="ResetUnitAnimation" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function ResetUnitAnimation takes unit whichUnit returns nothing
    call SetUnitAnimation(whichUnit, "stand")
endfunction
]]>
    </Function>

    <Function Name="SetUnitTimeScalePercent" ReturnType="nothing" ArgumentList="unit whichUnit, real percentScale">
      <![CDATA[function SetUnitTimeScalePercent takes unit whichUnit, real percentScale returns nothing
    call SetUnitTimeScale(whichUnit, percentScale * 0.01)
endfunction
]]>
    </Function>

    <Function Name="SetUnitScalePercent" ReturnType="nothing" ArgumentList="unit whichUnit, real percentScaleX, real percentScaleY, real percentScaleZ">
      <![CDATA[function SetUnitScalePercent takes unit whichUnit, real percentScaleX, real percentScaleY, real percentScaleZ returns nothing
    call SetUnitScale(whichUnit, percentScaleX * 0.01, percentScaleY * 0.01, percentScaleZ * 0.01)
endfunction
]]>
    </Function>

    <Function Name="SetUnitVertexColorBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real red, real green, real blue, real transparency">
      <![CDATA[function SetUnitVertexColorBJ takes unit whichUnit, real red, real green, real blue, real transparency returns nothing
    call SetUnitVertexColor(whichUnit, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="UnitAddIndicatorBJ" ReturnType="nothing" ArgumentList="unit whichUnit, real red, real green, real blue, real transparency">
      <![CDATA[function UnitAddIndicatorBJ takes unit whichUnit, real red, real green, real blue, real transparency returns nothing
    call AddIndicator(whichUnit, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="DestructableAddIndicatorBJ" ReturnType="nothing" ArgumentList="destructable whichDestructable, real red, real green, real blue, real transparency">
      <![CDATA[function DestructableAddIndicatorBJ takes destructable whichDestructable, real red, real green, real blue, real transparency returns nothing
    call AddIndicator(whichDestructable, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="ItemAddIndicatorBJ" ReturnType="nothing" ArgumentList="item whichItem, real red, real green, real blue, real transparency">
      <![CDATA[function ItemAddIndicatorBJ takes item whichItem, real red, real green, real blue, real transparency returns nothing
    call AddIndicator(whichItem, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="SetUnitFacingToFaceLocTimed" ReturnType="nothing" ArgumentList="unit whichUnit, location target, real duration">
      <![CDATA[function SetUnitFacingToFaceLocTimed takes unit whichUnit, location target, real duration returns nothing
    local location unitLoc = GetUnitLoc(whichUnit)

    call SetUnitFacingTimed(whichUnit, AngleBetweenPoints(unitLoc, target), duration)
    call RemoveLocation(unitLoc)
endfunction
]]>
    </Function>

    <Function Name="SetUnitFacingToFaceUnitTimed" ReturnType="nothing" ArgumentList="unit whichUnit, unit target, real duration">
      <![CDATA[function SetUnitFacingToFaceUnitTimed takes unit whichUnit, unit target, real duration returns nothing
    local location unitLoc = GetUnitLoc(target)

    call SetUnitFacingToFaceLocTimed(whichUnit, unitLoc, duration)
    call RemoveLocation(unitLoc)
endfunction
]]>
    </Function>

    <Function Name="QueueUnitAnimationBJ" ReturnType="nothing" ArgumentList="unit whichUnit, string whichAnimation">
      <![CDATA[function QueueUnitAnimationBJ takes unit whichUnit, string whichAnimation returns nothing
    call QueueUnitAnimation(whichUnit, whichAnimation)
endfunction
]]>
    </Function>

    <Function Name="SetDestructableAnimationBJ" ReturnType="nothing" ArgumentList="destructable d, string whichAnimation">
      <![CDATA[function SetDestructableAnimationBJ takes destructable d, string whichAnimation returns nothing
    call SetDestructableAnimation(d, whichAnimation)
endfunction
]]>
    </Function>

    <Function Name="QueueDestructableAnimationBJ" ReturnType="nothing" ArgumentList="destructable d, string whichAnimation">
      <![CDATA[function QueueDestructableAnimationBJ takes destructable d, string whichAnimation returns nothing
    call QueueDestructableAnimation(d, whichAnimation)
endfunction
]]>
    </Function>

    <Function Name="SetDestAnimationSpeedPercent" ReturnType="nothing" ArgumentList="destructable d, real percentScale">
      <![CDATA[function SetDestAnimationSpeedPercent takes destructable d, real percentScale returns nothing
    call SetDestructableAnimationSpeed(d, percentScale * 0.01)
endfunction
]]>
    </Function>

    <Function Name="DialogDisplayBJ" ReturnType="nothing" ArgumentList="boolean flag, dialog whichDialog, player whichPlayer">
      <![CDATA[function DialogDisplayBJ takes boolean flag, dialog whichDialog, player whichPlayer returns nothing
    call DialogDisplay(whichPlayer, whichDialog, flag)
endfunction
]]>
    </Function>

    <Function Name="DialogSetMessageBJ" ReturnType="nothing" ArgumentList="dialog whichDialog, string message">
      <![CDATA[function DialogSetMessageBJ takes dialog whichDialog, string message returns nothing
    call DialogSetMessage(whichDialog, message)
endfunction
]]>
    </Function>

    <Function Name="DialogAddButtonBJ" ReturnType="button" ArgumentList="dialog whichDialog, string buttonText">
      <![CDATA[function DialogAddButtonBJ takes dialog whichDialog, string buttonText returns button
    set bj_lastCreatedButton = DialogAddButton(whichDialog, buttonText,0)
    return bj_lastCreatedButton
endfunction
]]>
    </Function>

    <Function Name="DialogAddButtonWithHotkeyBJ" ReturnType="button" ArgumentList="dialog whichDialog, string buttonText, integer hotkey">
      <![CDATA[function DialogAddButtonWithHotkeyBJ takes dialog whichDialog, string buttonText, integer hotkey returns button
    set bj_lastCreatedButton = DialogAddButton(whichDialog, buttonText,hotkey)
    return bj_lastCreatedButton
endfunction
]]>
    </Function>

    <Function Name="DialogClearBJ" ReturnType="nothing" ArgumentList="dialog whichDialog">
      <![CDATA[function DialogClearBJ takes dialog whichDialog returns nothing
    call DialogClear(whichDialog)
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedButtonBJ" ReturnType="button" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedButtonBJ takes nothing returns button
    return bj_lastCreatedButton
endfunction
]]>
    </Function>

    <Function Name="GetClickedButtonBJ" ReturnType="button" ArgumentList="nothing">
      <![CDATA[function GetClickedButtonBJ takes nothing returns button
    return GetClickedButton()
endfunction
]]>
    </Function>

    <Function Name="GetClickedDialogBJ" ReturnType="dialog" ArgumentList="nothing">
      <![CDATA[function GetClickedDialogBJ takes nothing returns dialog
    return GetClickedDialog()
endfunction
]]>
    </Function>

    <Function Name="SetPlayerAllianceBJ" ReturnType="nothing" ArgumentList="player sourcePlayer, alliancetype whichAllianceSetting, boolean value, player otherPlayer">
      <![CDATA[function SetPlayerAllianceBJ takes player sourcePlayer, alliancetype whichAllianceSetting, boolean value, player otherPlayer returns nothing
    // Prevent players from attempting to ally with themselves.
    if (sourcePlayer == otherPlayer) then
        return
    endif

    call SetPlayerAlliance(sourcePlayer, otherPlayer, whichAllianceSetting, value)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerAllianceStateAllyBJ" ReturnType="nothing" ArgumentList="player sourcePlayer, player otherPlayer, boolean flag">
      <![CDATA[function SetPlayerAllianceStateAllyBJ takes player sourcePlayer, player otherPlayer, boolean flag returns nothing
    call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_PASSIVE,       flag)
    call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_HELP_REQUEST,  flag)
    call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_HELP_RESPONSE, flag)
    call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_XP,     flag)
    call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_SPELLS, flag)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerAllianceStateVisionBJ" ReturnType="nothing" ArgumentList="player sourcePlayer, player otherPlayer, boolean flag">
      <![CDATA[function SetPlayerAllianceStateVisionBJ takes player sourcePlayer, player otherPlayer, boolean flag returns nothing
    call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_VISION, flag)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerAllianceStateControlBJ" ReturnType="nothing" ArgumentList="player sourcePlayer, player otherPlayer, boolean flag">
      <![CDATA[function SetPlayerAllianceStateControlBJ takes player sourcePlayer, player otherPlayer, boolean flag returns nothing
    call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_CONTROL, flag)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerAllianceStateFullControlBJ" ReturnType="nothing" ArgumentList="player sourcePlayer, player otherPlayer, boolean flag">
      <![CDATA[function SetPlayerAllianceStateFullControlBJ takes player sourcePlayer, player otherPlayer, boolean flag returns nothing
    call SetPlayerAlliance(sourcePlayer, otherPlayer, ALLIANCE_SHARED_ADVANCED_CONTROL, flag)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerAllianceStateBJ" ReturnType="nothing" ArgumentList="player sourcePlayer, player otherPlayer, integer allianceState">
      <![CDATA[function SetPlayerAllianceStateBJ takes player sourcePlayer, player otherPlayer, integer allianceState returns nothing
    // Prevent players from attempting to ally with themselves.
    if (sourcePlayer == otherPlayer) then
        return
    endif

    if allianceState == bj_ALLIANCE_UNALLIED then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_UNALLIED_VISION then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_ALLIED then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_ALLIED_VISION then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_ALLIED_UNITS then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
    elseif allianceState == bj_ALLIANCE_ALLIED_ADVUNITS then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, true  )
    elseif allianceState == bj_ALLIANCE_NEUTRAL then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
        call SetPlayerAlliance( sourcePlayer, otherPlayer, ALLIANCE_PASSIVE, true )
    elseif allianceState == bj_ALLIANCE_NEUTRAL_VISION then
        call SetPlayerAllianceStateAllyBJ(        sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateVisionBJ(      sourcePlayer, otherPlayer, true  )
        call SetPlayerAllianceStateControlBJ(     sourcePlayer, otherPlayer, false )
        call SetPlayerAllianceStateFullControlBJ( sourcePlayer, otherPlayer, false )
        call SetPlayerAlliance( sourcePlayer, otherPlayer, ALLIANCE_PASSIVE, true )
    else
        // Unrecognized alliance state - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="SetForceAllianceStateBJ" ReturnType="nothing" ArgumentList="force sourceForce, force targetForce, integer allianceState">
      <![CDATA[function SetForceAllianceStateBJ takes force sourceForce, force targetForce, integer allianceState returns nothing
    local integer sourceIndex
    local integer targetIndex

    set sourceIndex = 0
    loop

        set targetIndex = 0
        loop
            call SetPlayerAllianceStateBJ(Player(sourceIndex), Player(targetIndex), allianceState)

            set targetIndex = targetIndex + 1
            exitwhen targetIndex == bj_MAX_PLAYER_SLOTS
        endloop

        set sourceIndex = sourceIndex + 1
        exitwhen sourceIndex == bj_MAX_PLAYER_SLOTS
    endloop
endfunction
]]>
    </Function>

    <Function Name="PlayersAreCoAllied" ReturnType="boolean" ArgumentList="player playerA, player playerB">
      <![CDATA[function PlayersAreCoAllied takes player playerA, player playerB returns boolean
    // Players are considered to be allied with themselves.
    if (playerA == playerB) then
        return true
    endif

    // Co-allies are both allied with each other.
    if GetPlayerAlliance(playerA, playerB, ALLIANCE_PASSIVE) then
        if GetPlayerAlliance(playerB, playerA, ALLIANCE_PASSIVE) then
            return true
        endif
    endif
    return false
endfunction
]]>
    </Function>

    <Function Name="ShareEverythingWithTeamAI" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function ShareEverythingWithTeamAI takes player whichPlayer returns nothing
    local integer playerIndex
    local player  indexPlayer

    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if (PlayersAreCoAllied(whichPlayer, indexPlayer) and whichPlayer != indexPlayer) then
            if (GetPlayerController(indexPlayer) == MAP_CONTROL_COMPUTER) then
                call SetPlayerAlliance(whichPlayer, indexPlayer, ALLIANCE_SHARED_VISION, true)
                call SetPlayerAlliance(whichPlayer, indexPlayer, ALLIANCE_SHARED_CONTROL, true)
                call SetPlayerAlliance(whichPlayer, indexPlayer, ALLIANCE_SHARED_ADVANCED_CONTROL, true)
            endif
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="ShareEverythingWithTeam" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function ShareEverythingWithTeam takes player whichPlayer returns nothing
    local integer playerIndex
    local player  indexPlayer

    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if (PlayersAreCoAllied(whichPlayer, indexPlayer) and whichPlayer != indexPlayer) then
            call SetPlayerAlliance(whichPlayer, indexPlayer, ALLIANCE_SHARED_VISION, true)
            call SetPlayerAlliance(whichPlayer, indexPlayer, ALLIANCE_SHARED_CONTROL, true)
            call SetPlayerAlliance(indexPlayer, whichPlayer, ALLIANCE_SHARED_CONTROL, true)
            call SetPlayerAlliance(whichPlayer, indexPlayer, ALLIANCE_SHARED_ADVANCED_CONTROL, true)
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="ConfigureNeutralVictim" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function ConfigureNeutralVictim takes nothing returns nothing
    local integer index
    local player indexPlayer
    local player neutralVictim = Player(bj_PLAYER_NEUTRAL_VICTIM)

    set index = 0
    loop
        set indexPlayer = Player(index)

        call SetPlayerAlliance(neutralVictim, indexPlayer, ALLIANCE_PASSIVE, true)
        call SetPlayerAlliance(indexPlayer, neutralVictim, ALLIANCE_PASSIVE, false)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop

    // Neutral Victim and Neutral Aggressive should not fight each other.
    set indexPlayer = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    call SetPlayerAlliance(neutralVictim, indexPlayer, ALLIANCE_PASSIVE, true)
    call SetPlayerAlliance(indexPlayer, neutralVictim, ALLIANCE_PASSIVE, true)

    // Neutral Victim does not give bounties.
    call SetPlayerState(neutralVictim, PLAYER_STATE_GIVES_BOUNTY, 0)
endfunction
]]>
    </Function>

    <Function Name="MakeUnitsPassiveForPlayerEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MakeUnitsPassiveForPlayerEnum takes nothing returns nothing
    call SetUnitOwner(GetEnumUnit(), Player(bj_PLAYER_NEUTRAL_VICTIM), false)
endfunction
]]>
    </Function>

    <Function Name="MakeUnitsPassiveForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function MakeUnitsPassiveForPlayer takes player whichPlayer returns nothing
    local group   playerUnits = CreateGroup()
    call CachePlayerHeroData(whichPlayer)
    call GroupEnumUnitsOfPlayer(playerUnits, whichPlayer, null)
    call ForGroup(playerUnits, function MakeUnitsPassiveForPlayerEnum)
    call DestroyGroup(playerUnits)
endfunction
]]>
    </Function>

    <Function Name="MakeUnitsPassiveForTeam" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function MakeUnitsPassiveForTeam takes player whichPlayer returns nothing
    local integer playerIndex
    local player  indexPlayer

    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if PlayersAreCoAllied(whichPlayer, indexPlayer) then
            call MakeUnitsPassiveForPlayer(indexPlayer)
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="AllowVictoryDefeat" ReturnType="boolean" ArgumentList="playergameresult gameResult">
      <![CDATA[function AllowVictoryDefeat takes playergameresult gameResult returns boolean
    if (gameResult == PLAYER_GAME_RESULT_VICTORY) then
        return not IsNoVictoryCheat()
    endif
    if (gameResult == PLAYER_GAME_RESULT_DEFEAT) then
        return not IsNoDefeatCheat()
    endif
    if (gameResult == PLAYER_GAME_RESULT_NEUTRAL) then
        return (not IsNoVictoryCheat()) and (not IsNoDefeatCheat())
    endif
    return true
endfunction
]]>
    </Function>

    <Function Name="EndGameBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function EndGameBJ takes nothing returns nothing
    call EndGame( true )
endfunction
]]>
    </Function>

    <Function Name="MeleeVictoryDialogBJ" ReturnType="nothing" ArgumentList="player whichPlayer, boolean leftGame">
      <![CDATA[function MeleeVictoryDialogBJ takes player whichPlayer, boolean leftGame returns nothing
    local trigger t = CreateTrigger()
    local dialog  d = DialogCreate()
    local string formatString

    // Display "player was victorious" or "player has left the game" message
    if (leftGame) then
        set formatString = GetLocalizedString( "PLAYER_LEFT_GAME" )
    else
        set formatString = GetLocalizedString( "PLAYER_VICTORIOUS" )
    endif

    call DisplayTimedTextFromPlayer(whichPlayer, 0, 0, 60, formatString)

    call DialogSetMessage( d, GetLocalizedString( "GAMEOVER_VICTORY_MSG" ) )
    call DialogAddButton( d, GetLocalizedString( "GAMEOVER_CONTINUE_GAME" ), GetLocalizedHotkey("GAMEOVER_CONTINUE_GAME") )

    set t = CreateTrigger()
    call TriggerRegisterDialogButtonEvent( t, DialogAddQuitButton( d, true, GetLocalizedString( "GAMEOVER_QUIT_GAME" ), GetLocalizedHotkey("GAMEOVER_QUIT_GAME") ) )

    call DialogDisplay( whichPlayer, d, true )
    call StartSoundForPlayerBJ( whichPlayer, bj_victoryDialogSound )
endfunction
]]>
    </Function>

    <Function Name="MeleeDefeatDialogBJ" ReturnType="nothing" ArgumentList="player whichPlayer, boolean leftGame">
      <![CDATA[function MeleeDefeatDialogBJ takes player whichPlayer, boolean leftGame returns nothing
    local trigger t = CreateTrigger()
    local dialog  d = DialogCreate()
    local string formatString

    // Display "player was defeated" or "player has left the game" message
    if (leftGame) then
        set formatString = GetLocalizedString( "PLAYER_LEFT_GAME" )
    else
        set formatString = GetLocalizedString( "PLAYER_DEFEATED" )
    endif

    call DisplayTimedTextFromPlayer(whichPlayer, 0, 0, 60, formatString)

    call DialogSetMessage( d, GetLocalizedString( "GAMEOVER_DEFEAT_MSG" ) )

    // Only show the continue button if the game is not over and observers on death are allowed
    if (not bj_meleeGameOver and IsMapFlagSet(MAP_OBSERVERS_ON_DEATH)) then
        call DialogAddButton( d, GetLocalizedString( "GAMEOVER_CONTINUE_OBSERVING" ), GetLocalizedHotkey("GAMEOVER_CONTINUE_OBSERVING") )
    endif

    set t = CreateTrigger()
    call TriggerRegisterDialogButtonEvent( t, DialogAddQuitButton( d, true, GetLocalizedString( "GAMEOVER_QUIT_GAME" ), GetLocalizedHotkey("GAMEOVER_QUIT_GAME") ) )

    call DialogDisplay( whichPlayer, d, true )
    call StartSoundForPlayerBJ( whichPlayer, bj_defeatDialogSound )
endfunction
]]>
    </Function>

    <Function Name="GameOverDialogBJ" ReturnType="nothing" ArgumentList="player whichPlayer, boolean leftGame">
      <![CDATA[function GameOverDialogBJ takes player whichPlayer, boolean leftGame returns nothing
    local trigger t = CreateTrigger()
    local dialog  d = DialogCreate()
    local string  s

    // Display "player left the game" message
    call DisplayTimedTextFromPlayer(whichPlayer, 0, 0, 60, GetLocalizedString( "PLAYER_LEFT_GAME" ))

    if (GetIntegerGameState(GAME_STATE_DISCONNECTED) != 0) then
        set s = GetLocalizedString( "GAMEOVER_DISCONNECTED" )
    else
        set s = GetLocalizedString( "GAMEOVER_GAME_OVER" )
    endif

    call DialogSetMessage( d, s )

    set t = CreateTrigger()
    call TriggerRegisterDialogButtonEvent( t, DialogAddQuitButton( d, true, GetLocalizedString( "GAMEOVER_OK" ), GetLocalizedHotkey("GAMEOVER_OK") ) )

    call DialogDisplay( whichPlayer, d, true )
    call StartSoundForPlayerBJ( whichPlayer, bj_defeatDialogSound )
endfunction
]]>
    </Function>

    <Function Name="RemovePlayerPreserveUnitsBJ" ReturnType="nothing" ArgumentList="player whichPlayer, playergameresult gameResult, boolean leftGame">
      <![CDATA[function RemovePlayerPreserveUnitsBJ takes player whichPlayer, playergameresult gameResult, boolean leftGame returns nothing
    if AllowVictoryDefeat(gameResult) then

        call RemovePlayer(whichPlayer, gameResult)

        if( gameResult == PLAYER_GAME_RESULT_VICTORY ) then
            call MeleeVictoryDialogBJ( whichPlayer, leftGame )
            return
        elseif( gameResult == PLAYER_GAME_RESULT_DEFEAT ) then
            call MeleeDefeatDialogBJ( whichPlayer, leftGame )
        else
            call GameOverDialogBJ( whichPlayer, leftGame )
        endif

    endif
endfunction
]]>
    </Function>

    <Function Name="CustomVictoryOkBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CustomVictoryOkBJ takes nothing returns nothing
    if bj_isSinglePlayer then
        call PauseGame( false )
        // Bump the difficulty back up to the default.
        call SetGameDifficulty(GetDefaultDifficulty())
    endif

    if (bj_changeLevelMapName == null) then
        call EndGame( bj_changeLevelShowScores )
    else
        call ChangeLevel( bj_changeLevelMapName, bj_changeLevelShowScores )
    endif
endfunction
]]>
    </Function>

    <Function Name="CustomVictoryQuitBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CustomVictoryQuitBJ takes nothing returns nothing
    if bj_isSinglePlayer then
        call PauseGame( false )
        // Bump the difficulty back up to the default.
        call SetGameDifficulty(GetDefaultDifficulty())
    endif

    call EndGame( bj_changeLevelShowScores )
endfunction
]]>
    </Function>

    <Function Name="CustomVictoryDialogBJ" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function CustomVictoryDialogBJ takes player whichPlayer returns nothing
    local trigger t = CreateTrigger()
    local dialog  d = DialogCreate()

    call DialogSetMessage( d, GetLocalizedString( "GAMEOVER_VICTORY_MSG" ) )

    set t = CreateTrigger()
    call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_CONTINUE" ), GetLocalizedHotkey("GAMEOVER_CONTINUE") ) )
    call TriggerAddAction( t, function CustomVictoryOkBJ )

    set t = CreateTrigger()
    call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_QUIT_MISSION" ), GetLocalizedHotkey("GAMEOVER_QUIT_MISSION") ) )
    call TriggerAddAction( t, function CustomVictoryQuitBJ )

    if (GetLocalPlayer() == whichPlayer) then
        call EnableUserControl( true )
        if bj_isSinglePlayer then
            call PauseGame( true )
        endif
    endif

    call EnableUserUI(false)
    call DialogDisplay( whichPlayer, d, true )
    call VolumeGroupSetVolumeForPlayerBJ( whichPlayer, SOUND_VOLUMEGROUP_UI, 1.0 )
    call StartSoundForPlayerBJ( whichPlayer, bj_victoryDialogSound )
endfunction
]]>
    </Function>

    <Function Name="CustomVictorySkipBJ" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function CustomVictorySkipBJ takes player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        if bj_isSinglePlayer then
            // Bump the difficulty back up to the default.
            call SetGameDifficulty(GetDefaultDifficulty())
        endif

        if (bj_changeLevelMapName == null) then
            call EndGame( bj_changeLevelShowScores )
        else
            call ChangeLevel( bj_changeLevelMapName, bj_changeLevelShowScores )
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="CustomVictoryBJ" ReturnType="nothing" ArgumentList="player whichPlayer, boolean showDialog, boolean showScores">
      <![CDATA[function CustomVictoryBJ takes player whichPlayer, boolean showDialog, boolean showScores returns nothing
    if AllowVictoryDefeat( PLAYER_GAME_RESULT_VICTORY ) then
        call RemovePlayer( whichPlayer, PLAYER_GAME_RESULT_VICTORY )

        if not bj_isSinglePlayer then
            call DisplayTimedTextFromPlayer(whichPlayer, 0, 0, 60, GetLocalizedString( "PLAYER_VICTORIOUS" ) )
        endif

        // UI only needs to be displayed to users.
        if (GetPlayerController(whichPlayer) == MAP_CONTROL_USER) then
            set bj_changeLevelShowScores = showScores
            if showDialog then
                call CustomVictoryDialogBJ( whichPlayer )
            else
                call CustomVictorySkipBJ( whichPlayer )
            endif
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="CustomDefeatRestartBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CustomDefeatRestartBJ takes nothing returns nothing
    call PauseGame( false )
    call RestartGame( true )
endfunction
]]>
    </Function>

    <Function Name="CustomDefeatReduceDifficultyBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CustomDefeatReduceDifficultyBJ takes nothing returns nothing
    local gamedifficulty diff = GetGameDifficulty()

    call PauseGame( false )

    // Knock the difficulty down, if possible.
    if (diff == MAP_DIFFICULTY_EASY) then
        // Sorry, but it doesn't get any easier than this.
    elseif (diff == MAP_DIFFICULTY_NORMAL) then
        call SetGameDifficulty(MAP_DIFFICULTY_EASY)
    elseif (diff == MAP_DIFFICULTY_HARD) then
        call SetGameDifficulty(MAP_DIFFICULTY_NORMAL)
    else
        // Unrecognized difficulty
    endif

    call RestartGame( true )
endfunction
]]>
    </Function>

    <Function Name="CustomDefeatLoadBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CustomDefeatLoadBJ takes nothing returns nothing
    call PauseGame( false )
    call DisplayLoadDialog()
endfunction
]]>
    </Function>

    <Function Name="CustomDefeatQuitBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CustomDefeatQuitBJ takes nothing returns nothing
    if bj_isSinglePlayer then
        call PauseGame( false )
    endif

    // Bump the difficulty back up to the default.
    call SetGameDifficulty(GetDefaultDifficulty())
    call EndGame( true )
endfunction
]]>
    </Function>

    <Function Name="CustomDefeatDialogBJ" ReturnType="nothing" ArgumentList="player whichPlayer, string message">
      <![CDATA[function CustomDefeatDialogBJ takes player whichPlayer, string message returns nothing
    local trigger t = CreateTrigger()
    local dialog  d = DialogCreate()

    call DialogSetMessage( d, message )

    if bj_isSinglePlayer then
        set t = CreateTrigger()
        call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_RESTART" ), GetLocalizedHotkey("GAMEOVER_RESTART") ) )
        call TriggerAddAction( t, function CustomDefeatRestartBJ )

        if (GetGameDifficulty() != MAP_DIFFICULTY_EASY) then
            set t = CreateTrigger()
            call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_REDUCE_DIFFICULTY" ), GetLocalizedHotkey("GAMEOVER_REDUCE_DIFFICULTY") ) )
            call TriggerAddAction( t, function CustomDefeatReduceDifficultyBJ )
        endif

        set t = CreateTrigger()
        call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_LOAD" ), GetLocalizedHotkey("GAMEOVER_LOAD") ) )
        call TriggerAddAction( t, function CustomDefeatLoadBJ )
    endif

    set t = CreateTrigger()
    call TriggerRegisterDialogButtonEvent( t, DialogAddButton( d, GetLocalizedString( "GAMEOVER_QUIT_MISSION" ), GetLocalizedHotkey("GAMEOVER_QUIT_MISSION") ) )
    call TriggerAddAction( t, function CustomDefeatQuitBJ )

    if (GetLocalPlayer() == whichPlayer) then
        call EnableUserControl( true )
        if bj_isSinglePlayer then
            call PauseGame( true )
        endif
    endif

    call EnableUserUI(false)
    call DialogDisplay( whichPlayer, d, true )
    call VolumeGroupSetVolumeForPlayerBJ( whichPlayer, SOUND_VOLUMEGROUP_UI, 1.0 )
    call StartSoundForPlayerBJ( whichPlayer, bj_defeatDialogSound )
endfunction
]]>
    </Function>

    <Function Name="CustomDefeatBJ" ReturnType="nothing" ArgumentList="player whichPlayer, string message">
      <![CDATA[function CustomDefeatBJ takes player whichPlayer, string message returns nothing
    if AllowVictoryDefeat( PLAYER_GAME_RESULT_DEFEAT ) then
        call RemovePlayer( whichPlayer, PLAYER_GAME_RESULT_DEFEAT )

        if not bj_isSinglePlayer then
            call DisplayTimedTextFromPlayer(whichPlayer, 0, 0, 60, GetLocalizedString( "PLAYER_DEFEATED" ) )
        endif

        // UI only needs to be displayed to users.
        if (GetPlayerController(whichPlayer) == MAP_CONTROL_USER) then
            call CustomDefeatDialogBJ( whichPlayer, message )
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="SetNextLevelBJ" ReturnType="nothing" ArgumentList="string nextLevel">
      <![CDATA[function SetNextLevelBJ takes string nextLevel returns nothing
    if (nextLevel == "") then
        set bj_changeLevelMapName = null
    else
        set bj_changeLevelMapName = nextLevel
    endif
endfunction
]]>
    </Function>

    <Function Name="SetPlayerOnScoreScreenBJ" ReturnType="nothing" ArgumentList="boolean flag, player whichPlayer">
      <![CDATA[function SetPlayerOnScoreScreenBJ takes boolean flag, player whichPlayer returns nothing
    call SetPlayerOnScoreScreen(whichPlayer, flag)
endfunction
]]>
    </Function>

    <Function Name="CreateQuestBJ" ReturnType="quest" ArgumentList="integer questType, string title, string description, string iconPath">
      <![CDATA[function CreateQuestBJ takes integer questType, string title, string description, string iconPath returns quest
    local boolean required   = (questType == bj_QUESTTYPE_REQ_DISCOVERED) or (questType == bj_QUESTTYPE_REQ_UNDISCOVERED)
    local boolean discovered = (questType == bj_QUESTTYPE_REQ_DISCOVERED) or (questType == bj_QUESTTYPE_OPT_DISCOVERED)

    set bj_lastCreatedQuest = CreateQuest()
    call QuestSetTitle(bj_lastCreatedQuest, title)
    call QuestSetDescription(bj_lastCreatedQuest, description)
    call QuestSetIconPath(bj_lastCreatedQuest, iconPath)
    call QuestSetRequired(bj_lastCreatedQuest, required)
    call QuestSetDiscovered(bj_lastCreatedQuest, discovered)
    call QuestSetCompleted(bj_lastCreatedQuest, false)
    return bj_lastCreatedQuest
endfunction
]]>
    </Function>

    <Function Name="DestroyQuestBJ" ReturnType="nothing" ArgumentList="quest whichQuest">
      <![CDATA[function DestroyQuestBJ takes quest whichQuest returns nothing
    call DestroyQuest(whichQuest)
endfunction
]]>
    </Function>

    <Function Name="QuestSetEnabledBJ" ReturnType="nothing" ArgumentList="boolean enabled, quest whichQuest">
      <![CDATA[function QuestSetEnabledBJ takes boolean enabled, quest whichQuest returns nothing
    call QuestSetEnabled(whichQuest, enabled)
endfunction
]]>
    </Function>

    <Function Name="QuestSetTitleBJ" ReturnType="nothing" ArgumentList="quest whichQuest, string title">
      <![CDATA[function QuestSetTitleBJ takes quest whichQuest, string title returns nothing
    call QuestSetTitle(whichQuest, title)
endfunction
]]>
    </Function>

    <Function Name="QuestSetDescriptionBJ" ReturnType="nothing" ArgumentList="quest whichQuest, string description">
      <![CDATA[function QuestSetDescriptionBJ takes quest whichQuest, string description returns nothing
    call QuestSetDescription(whichQuest, description)
endfunction
]]>
    </Function>

    <Function Name="QuestSetCompletedBJ" ReturnType="nothing" ArgumentList="quest whichQuest, boolean completed">
      <![CDATA[function QuestSetCompletedBJ takes quest whichQuest, boolean completed returns nothing
    call QuestSetCompleted(whichQuest, completed)
endfunction
]]>
    </Function>

    <Function Name="QuestSetFailedBJ" ReturnType="nothing" ArgumentList="quest whichQuest, boolean failed">
      <![CDATA[function QuestSetFailedBJ takes quest whichQuest, boolean failed returns nothing
    call QuestSetFailed(whichQuest, failed)
endfunction
]]>
    </Function>

    <Function Name="QuestSetDiscoveredBJ" ReturnType="nothing" ArgumentList="quest whichQuest, boolean discovered">
      <![CDATA[function QuestSetDiscoveredBJ takes quest whichQuest, boolean discovered returns nothing
    call QuestSetDiscovered(whichQuest, discovered)
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedQuestBJ" ReturnType="quest" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedQuestBJ takes nothing returns quest
    return bj_lastCreatedQuest
endfunction
]]>
    </Function>

    <Function Name="CreateQuestItemBJ" ReturnType="questitem" ArgumentList="quest whichQuest, string description">
      <![CDATA[function CreateQuestItemBJ takes quest whichQuest, string description returns questitem
    set bj_lastCreatedQuestItem = QuestCreateItem(whichQuest)
    call QuestItemSetDescription(bj_lastCreatedQuestItem, description)
    call QuestItemSetCompleted(bj_lastCreatedQuestItem, false)
    return bj_lastCreatedQuestItem
endfunction
]]>
    </Function>

    <Function Name="QuestItemSetDescriptionBJ" ReturnType="nothing" ArgumentList="questitem whichQuestItem, string description">
      <![CDATA[function QuestItemSetDescriptionBJ takes questitem whichQuestItem, string description returns nothing
    call QuestItemSetDescription(whichQuestItem, description)
endfunction
]]>
    </Function>

    <Function Name="QuestItemSetCompletedBJ" ReturnType="nothing" ArgumentList="questitem whichQuestItem, boolean completed">
      <![CDATA[function QuestItemSetCompletedBJ takes questitem whichQuestItem, boolean completed returns nothing
    call QuestItemSetCompleted(whichQuestItem, completed)
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedQuestItemBJ" ReturnType="questitem" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedQuestItemBJ takes nothing returns questitem
    return bj_lastCreatedQuestItem
endfunction
]]>
    </Function>

    <Function Name="CreateDefeatConditionBJ" ReturnType="defeatcondition" ArgumentList="string description">
      <![CDATA[function CreateDefeatConditionBJ takes string description returns defeatcondition
    set bj_lastCreatedDefeatCondition = CreateDefeatCondition()
    call DefeatConditionSetDescription(bj_lastCreatedDefeatCondition, description)
    return bj_lastCreatedDefeatCondition
endfunction
]]>
    </Function>

    <Function Name="DestroyDefeatConditionBJ" ReturnType="nothing" ArgumentList="defeatcondition whichCondition">
      <![CDATA[function DestroyDefeatConditionBJ takes defeatcondition whichCondition returns nothing
    call DestroyDefeatCondition(whichCondition)
endfunction
]]>
    </Function>

    <Function Name="DefeatConditionSetDescriptionBJ" ReturnType="nothing" ArgumentList="defeatcondition whichCondition, string description">
      <![CDATA[function DefeatConditionSetDescriptionBJ takes defeatcondition whichCondition, string description returns nothing
    call DefeatConditionSetDescription(whichCondition, description)
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedDefeatConditionBJ" ReturnType="defeatcondition" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedDefeatConditionBJ takes nothing returns defeatcondition
    return bj_lastCreatedDefeatCondition
endfunction
]]>
    </Function>

    <Function Name="FlashQuestDialogButtonBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function FlashQuestDialogButtonBJ takes nothing returns nothing
    call FlashQuestDialogButton()
endfunction
]]>
    </Function>

    <Function Name="QuestMessageBJ" ReturnType="nothing" ArgumentList="force f, integer messageType, string message">
      <![CDATA[function QuestMessageBJ takes force f, integer messageType, string message returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), f)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        if (messageType == bj_QUESTMESSAGE_DISCOVERED) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUEST, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUEST, message)
            call StartSound(bj_questDiscoveredSound)
            call FlashQuestDialogButton()

        elseif (messageType == bj_QUESTMESSAGE_UPDATED) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUESTUPDATE, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUESTUPDATE, message)
            call StartSound(bj_questUpdatedSound)
            call FlashQuestDialogButton()

        elseif (messageType == bj_QUESTMESSAGE_COMPLETED) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUESTDONE, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUESTDONE, message)
            call StartSound(bj_questCompletedSound)
            call FlashQuestDialogButton()

        elseif (messageType == bj_QUESTMESSAGE_FAILED) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUESTFAILED, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUESTFAILED, message)
            call StartSound(bj_questFailedSound)
            call FlashQuestDialogButton()

        elseif (messageType == bj_QUESTMESSAGE_REQUIREMENT) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_QUESTREQUIREMENT, message)

        elseif (messageType == bj_QUESTMESSAGE_MISSIONFAILED) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_MISSIONFAILED, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_MISSIONFAILED, message)
            call StartSound(bj_questFailedSound)

        elseif (messageType == bj_QUESTMESSAGE_HINT) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_HINT, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_HINT, message)
            call StartSound(bj_questHintSound)

        elseif (messageType == bj_QUESTMESSAGE_ALWAYSHINT) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_ALWAYSHINT, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_ALWAYSHINT, message)
            call StartSound(bj_questHintSound)

        elseif (messageType == bj_QUESTMESSAGE_SECRET) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_SECRET, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_SECRET, message)
            call StartSound(bj_questSecretSound)

        elseif (messageType == bj_QUESTMESSAGE_UNITACQUIRED) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_UNITACQUIRED, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_UNITACQUIRED, message)
            call StartSound(bj_questHintSound)

        elseif (messageType == bj_QUESTMESSAGE_UNITAVAILABLE) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_UNITAVAILABLE, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_UNITAVAILABLE, message)
            call StartSound(bj_questHintSound)

        elseif (messageType == bj_QUESTMESSAGE_ITEMACQUIRED) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_ITEMACQUIRED, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_ITEMACQUIRED, message)
            call StartSound(bj_questItemAcquiredSound)

        elseif (messageType == bj_QUESTMESSAGE_WARNING) then
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_WARNING, " ")
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_TEXT_DELAY_WARNING, message)
            call StartSound(bj_questWarningSound)

        else
            // Unrecognized message type - ignore the request.
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="StartTimerBJ" ReturnType="timer" ArgumentList="timer t, boolean periodic, real timeout">
      <![CDATA[function StartTimerBJ takes timer t, boolean periodic, real timeout returns timer
    set bj_lastStartedTimer = t
    call TimerStart(t, timeout, periodic, null)
    return bj_lastStartedTimer
endfunction
]]>
    </Function>

    <Function Name="CreateTimerBJ" ReturnType="timer" ArgumentList="boolean periodic, real timeout">
      <![CDATA[function CreateTimerBJ takes boolean periodic, real timeout returns timer
    set bj_lastStartedTimer = CreateTimer()
    call TimerStart(bj_lastStartedTimer, timeout, periodic, null)
    return bj_lastStartedTimer
endfunction
]]>
    </Function>

    <Function Name="DestroyTimerBJ" ReturnType="nothing" ArgumentList="timer whichTimer">
      <![CDATA[function DestroyTimerBJ takes timer whichTimer returns nothing
    call DestroyTimer(whichTimer)
endfunction
]]>
    </Function>

    <Function Name="PauseTimerBJ" ReturnType="nothing" ArgumentList="boolean pause, timer whichTimer">
      <![CDATA[function PauseTimerBJ takes boolean pause, timer whichTimer returns nothing
    if pause then
        call PauseTimer(whichTimer)
    else
        call ResumeTimer(whichTimer)
    endif
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedTimerBJ" ReturnType="timer" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedTimerBJ takes nothing returns timer
    return bj_lastStartedTimer
endfunction
]]>
    </Function>

    <Function Name="CreateTimerDialogBJ" ReturnType="timerdialog" ArgumentList="timer t, string title">
      <![CDATA[function CreateTimerDialogBJ takes timer t, string title returns timerdialog
    set bj_lastCreatedTimerDialog = CreateTimerDialog(t)
    call TimerDialogSetTitle(bj_lastCreatedTimerDialog, title)
    call TimerDialogDisplay(bj_lastCreatedTimerDialog, true)
    return bj_lastCreatedTimerDialog
endfunction
]]>
    </Function>

    <Function Name="DestroyTimerDialogBJ" ReturnType="nothing" ArgumentList="timerdialog td">
      <![CDATA[function DestroyTimerDialogBJ takes timerdialog td returns nothing
    call DestroyTimerDialog(td)
endfunction
]]>
    </Function>

    <Function Name="TimerDialogSetTitleBJ" ReturnType="nothing" ArgumentList="timerdialog td, string title">
      <![CDATA[function TimerDialogSetTitleBJ takes timerdialog td, string title returns nothing
    call TimerDialogSetTitle(td, title)
endfunction
]]>
    </Function>

    <Function Name="TimerDialogSetTitleColorBJ" ReturnType="nothing" ArgumentList="timerdialog td, real red, real green, real blue, real transparency">
      <![CDATA[function TimerDialogSetTitleColorBJ takes timerdialog td, real red, real green, real blue, real transparency returns nothing
    call TimerDialogSetTitleColor(td, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="TimerDialogSetTimeColorBJ" ReturnType="nothing" ArgumentList="timerdialog td, real red, real green, real blue, real transparency">
      <![CDATA[function TimerDialogSetTimeColorBJ takes timerdialog td, real red, real green, real blue, real transparency returns nothing
    call TimerDialogSetTimeColor(td, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="TimerDialogSetSpeedBJ" ReturnType="nothing" ArgumentList="timerdialog td, real speedMultFactor">
      <![CDATA[function TimerDialogSetSpeedBJ takes timerdialog td, real speedMultFactor returns nothing
    call TimerDialogSetSpeed(td, speedMultFactor)
endfunction
]]>
    </Function>

    <Function Name="TimerDialogDisplayForPlayerBJ" ReturnType="nothing" ArgumentList="boolean show, timerdialog td, player whichPlayer">
      <![CDATA[function TimerDialogDisplayForPlayerBJ takes boolean show, timerdialog td, player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call TimerDialogDisplay(td, show)
    endif
endfunction
]]>
    </Function>

    <Function Name="TimerDialogDisplayBJ" ReturnType="nothing" ArgumentList="boolean show, timerdialog td">
      <![CDATA[function TimerDialogDisplayBJ takes boolean show, timerdialog td returns nothing
    call TimerDialogDisplay(td, show)
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedTimerDialogBJ" ReturnType="timerdialog" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedTimerDialogBJ takes nothing returns timerdialog
    return bj_lastCreatedTimerDialog
endfunction
]]>
    </Function>

    <Function Name="LeaderboardResizeBJ" ReturnType="nothing" ArgumentList="leaderboard lb">
      <![CDATA[function LeaderboardResizeBJ takes leaderboard lb returns nothing
    local integer size = LeaderboardGetItemCount(lb)

    if (LeaderboardGetLabelText(lb) == "") then
        set size = size - 1
    endif
    call LeaderboardSetSizeByItemCount(lb, size)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetPlayerItemValueBJ" ReturnType="nothing" ArgumentList="player whichPlayer, leaderboard lb, integer val">
      <![CDATA[function LeaderboardSetPlayerItemValueBJ takes player whichPlayer, leaderboard lb, integer val returns nothing
    call LeaderboardSetItemValue(lb, LeaderboardGetPlayerIndex(lb, whichPlayer), val)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetPlayerItemLabelBJ" ReturnType="nothing" ArgumentList="player whichPlayer, leaderboard lb, string val">
      <![CDATA[function LeaderboardSetPlayerItemLabelBJ takes player whichPlayer, leaderboard lb, string val returns nothing
    call LeaderboardSetItemLabel(lb, LeaderboardGetPlayerIndex(lb, whichPlayer), val)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetPlayerItemStyleBJ" ReturnType="nothing" ArgumentList="player whichPlayer, leaderboard lb, boolean showLabel, boolean showValue, boolean showIcon">
      <![CDATA[function LeaderboardSetPlayerItemStyleBJ takes player whichPlayer, leaderboard lb, boolean showLabel, boolean showValue, boolean showIcon returns nothing
    call LeaderboardSetItemStyle(lb, LeaderboardGetPlayerIndex(lb, whichPlayer), showLabel, showValue, showIcon)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetPlayerItemLabelColorBJ" ReturnType="nothing" ArgumentList="player whichPlayer, leaderboard lb, real red, real green, real blue, real transparency">
      <![CDATA[function LeaderboardSetPlayerItemLabelColorBJ takes player whichPlayer, leaderboard lb, real red, real green, real blue, real transparency returns nothing
    call LeaderboardSetItemLabelColor(lb, LeaderboardGetPlayerIndex(lb, whichPlayer), PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetPlayerItemValueColorBJ" ReturnType="nothing" ArgumentList="player whichPlayer, leaderboard lb, real red, real green, real blue, real transparency">
      <![CDATA[function LeaderboardSetPlayerItemValueColorBJ takes player whichPlayer, leaderboard lb, real red, real green, real blue, real transparency returns nothing
    call LeaderboardSetItemValueColor(lb, LeaderboardGetPlayerIndex(lb, whichPlayer), PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetLabelColorBJ" ReturnType="nothing" ArgumentList="leaderboard lb, real red, real green, real blue, real transparency">
      <![CDATA[function LeaderboardSetLabelColorBJ takes leaderboard lb, real red, real green, real blue, real transparency returns nothing
    call LeaderboardSetLabelColor(lb, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetValueColorBJ" ReturnType="nothing" ArgumentList="leaderboard lb, real red, real green, real blue, real transparency">
      <![CDATA[function LeaderboardSetValueColorBJ takes leaderboard lb, real red, real green, real blue, real transparency returns nothing
    call LeaderboardSetValueColor(lb, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetLabelBJ" ReturnType="nothing" ArgumentList="leaderboard lb, string label">
      <![CDATA[function LeaderboardSetLabelBJ takes leaderboard lb, string label returns nothing
    call LeaderboardSetLabel(lb, label)
    call LeaderboardResizeBJ(lb)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSetStyleBJ" ReturnType="nothing" ArgumentList="leaderboard lb, boolean showLabel, boolean showNames, boolean showValues, boolean showIcons">
      <![CDATA[function LeaderboardSetStyleBJ takes leaderboard lb, boolean showLabel, boolean showNames, boolean showValues, boolean showIcons returns nothing
    call LeaderboardSetStyle(lb, showLabel, showNames, showValues, showIcons)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardGetItemCountBJ" ReturnType="integer" ArgumentList="leaderboard lb">
      <![CDATA[function LeaderboardGetItemCountBJ takes leaderboard lb returns integer
    return LeaderboardGetItemCount(lb)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardHasPlayerItemBJ" ReturnType="boolean" ArgumentList="leaderboard lb, player whichPlayer">
      <![CDATA[function LeaderboardHasPlayerItemBJ takes leaderboard lb, player whichPlayer returns boolean
    return LeaderboardHasPlayerItem(lb, whichPlayer)
endfunction
]]>
    </Function>

    <Function Name="ForceSetLeaderboardBJ" ReturnType="nothing" ArgumentList="leaderboard lb, force toForce">
      <![CDATA[function ForceSetLeaderboardBJ takes leaderboard lb, force toForce returns nothing
    local integer index
    local player  indexPlayer

    set index = 0
    loop
        set indexPlayer = Player(index)
        if IsPlayerInForce(indexPlayer, toForce) then
            call PlayerSetLeaderboard(indexPlayer, lb)
        endif
        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="CreateLeaderboardBJ" ReturnType="leaderboard" ArgumentList="force toForce, string label">
      <![CDATA[function CreateLeaderboardBJ takes force toForce, string label returns leaderboard
    set bj_lastCreatedLeaderboard = CreateLeaderboard()
    call LeaderboardSetLabel(bj_lastCreatedLeaderboard, label)
    call ForceSetLeaderboardBJ(bj_lastCreatedLeaderboard, toForce)
    call LeaderboardDisplay(bj_lastCreatedLeaderboard, true)
    return bj_lastCreatedLeaderboard
endfunction
]]>
    </Function>

    <Function Name="DestroyLeaderboardBJ" ReturnType="nothing" ArgumentList="leaderboard lb">
      <![CDATA[function DestroyLeaderboardBJ takes leaderboard lb returns nothing
    call DestroyLeaderboard(lb)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardDisplayBJ" ReturnType="nothing" ArgumentList="boolean show, leaderboard lb">
      <![CDATA[function LeaderboardDisplayBJ takes boolean show, leaderboard lb returns nothing
    call LeaderboardDisplay(lb, show)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardAddItemBJ" ReturnType="nothing" ArgumentList="player whichPlayer, leaderboard lb, string label, integer value">
      <![CDATA[function LeaderboardAddItemBJ takes player whichPlayer, leaderboard lb, string label, integer value returns nothing
    if (LeaderboardHasPlayerItem(lb, whichPlayer)) then
        call LeaderboardRemovePlayerItem(lb, whichPlayer)
    endif
    call LeaderboardAddItem(lb, label, value, whichPlayer)
    call LeaderboardResizeBJ(lb)
    //call LeaderboardSetSizeByItemCount(lb, LeaderboardGetItemCount(lb))
endfunction
]]>
    </Function>

    <Function Name="LeaderboardRemovePlayerItemBJ" ReturnType="nothing" ArgumentList="player whichPlayer, leaderboard lb">
      <![CDATA[function LeaderboardRemovePlayerItemBJ takes player whichPlayer, leaderboard lb returns nothing
    call LeaderboardRemovePlayerItem(lb, whichPlayer)
    call LeaderboardResizeBJ(lb)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSortItemsBJ" ReturnType="nothing" ArgumentList="leaderboard lb, integer sortType, boolean ascending">
      <![CDATA[function LeaderboardSortItemsBJ takes leaderboard lb, integer sortType, boolean ascending returns nothing
    if (sortType == bj_SORTTYPE_SORTBYVALUE) then
        call LeaderboardSortItemsByValue(lb, ascending)
    elseif (sortType == bj_SORTTYPE_SORTBYPLAYER) then
        call LeaderboardSortItemsByPlayer(lb, ascending)
    elseif (sortType == bj_SORTTYPE_SORTBYLABEL) then
        call LeaderboardSortItemsByLabel(lb, ascending)
    else
        // Unrecognized sort type - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSortItemsByPlayerBJ" ReturnType="nothing" ArgumentList="leaderboard lb, boolean ascending">
      <![CDATA[function LeaderboardSortItemsByPlayerBJ takes leaderboard lb, boolean ascending returns nothing
    call LeaderboardSortItemsByPlayer(lb, ascending)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardSortItemsByLabelBJ" ReturnType="nothing" ArgumentList="leaderboard lb, boolean ascending">
      <![CDATA[function LeaderboardSortItemsByLabelBJ takes leaderboard lb, boolean ascending returns nothing
    call LeaderboardSortItemsByLabel(lb, ascending)
endfunction
]]>
    </Function>

    <Function Name="LeaderboardGetPlayerIndexBJ" ReturnType="integer" ArgumentList="player whichPlayer, leaderboard lb">
      <![CDATA[function LeaderboardGetPlayerIndexBJ takes player whichPlayer, leaderboard lb returns integer
    return LeaderboardGetPlayerIndex(lb, whichPlayer) + 1
endfunction
]]>
    </Function>

    <Function Name="LeaderboardGetIndexedPlayerBJ" ReturnType="player" ArgumentList="integer position, leaderboard lb">
      <![CDATA[function LeaderboardGetIndexedPlayerBJ takes integer position, leaderboard lb returns player
    local integer index
    local player  indexPlayer

    set index = 0
    loop
        set indexPlayer = Player(index)
        if (LeaderboardGetPlayerIndex(lb, indexPlayer) == position - 1) then
            return indexPlayer
        endif

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop

    return Player(PLAYER_NEUTRAL_PASSIVE)
endfunction
]]>
    </Function>

    <Function Name="PlayerGetLeaderboardBJ" ReturnType="leaderboard" ArgumentList="player whichPlayer">
      <![CDATA[function PlayerGetLeaderboardBJ takes player whichPlayer returns leaderboard
    return PlayerGetLeaderboard(whichPlayer)
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedLeaderboard" ReturnType="leaderboard" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedLeaderboard takes nothing returns leaderboard
    return bj_lastCreatedLeaderboard
endfunction
]]>
    </Function>

    <Function Name="MultiboardAllowDisplayBJ" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[function MultiboardAllowDisplayBJ takes boolean flag returns nothing
    call MultiboardSuppressDisplay(not flag)
endfunction
]]>
    </Function>

    <Function Name="TextTagSize2Height" ReturnType="real" ArgumentList="real size">
      <![CDATA[function TextTagSize2Height takes real size returns real
    return size * 0.023 / 10
endfunction
]]>
    </Function>

    <Function Name="TextTagSpeed2Velocity" ReturnType="real" ArgumentList="real speed">
      <![CDATA[function TextTagSpeed2Velocity takes real speed returns real
    return speed * 0.071 / 128
endfunction
]]>
    </Function>

    <Function Name="SetTextTagColorBJ" ReturnType="nothing" ArgumentList="texttag tt, real red, real green, real blue, real transparency">
      <![CDATA[function SetTextTagColorBJ takes texttag tt, real red, real green, real blue, real transparency returns nothing
    call SetTextTagColor(tt, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction
]]>
    </Function>

    <Function Name="CreateTextTagLocBJ" ReturnType="texttag" ArgumentList="string s, location loc, real zOffset, real size, real red, real green, real blue, real transparency">
      <![CDATA[function CreateTextTagLocBJ takes string s, location loc, real zOffset, real size, real red, real green, real blue, real transparency returns texttag
    local real textHeight = TextTagSize2Height(size)

    set bj_lastCreatedTextTag = CreateTextTag()
    call SetTextTagText(bj_lastCreatedTextTag, s, textHeight)
    call SetTextTagPos(bj_lastCreatedTextTag, GetLocationX(loc), GetLocationY(loc), zOffset)
    call SetTextTagColorBJ(bj_lastCreatedTextTag, red, green, blue, transparency)

    return bj_lastCreatedTextTag
endfunction
]]>
    </Function>

    <Function Name="CreateTextTagUnitBJ" ReturnType="texttag" ArgumentList="string s, unit whichUnit, real zOffset, real size, real red, real green, real blue, real transparency">
      <![CDATA[function CreateTextTagUnitBJ takes string s, unit whichUnit, real zOffset, real size, real red, real green, real blue, real transparency returns texttag
    local real textHeight = TextTagSize2Height(size)

    set bj_lastCreatedTextTag = CreateTextTag()
    call SetTextTagText(bj_lastCreatedTextTag, s, textHeight)
    call SetTextTagPosUnit(bj_lastCreatedTextTag, whichUnit, zOffset)
    call SetTextTagColorBJ(bj_lastCreatedTextTag, red, green, blue, transparency)

    return bj_lastCreatedTextTag
endfunction
]]>
    </Function>

    <Function Name="DestroyTextTagBJ" ReturnType="nothing" ArgumentList="texttag tt">
      <![CDATA[function DestroyTextTagBJ takes texttag tt returns nothing
    call DestroyTextTag(tt)
endfunction
]]>
    </Function>

    <Function Name="SetTextTagVelocityBJ" ReturnType="nothing" ArgumentList="texttag tt, real speed, real angle">
      <![CDATA[function SetTextTagVelocityBJ takes texttag tt, real speed, real angle returns nothing
    local real vel = TextTagSpeed2Velocity(speed)
    local real xvel = vel * Cos(angle * bj_DEGTORAD)
    local real yvel = vel * Sin(angle * bj_DEGTORAD)

    call SetTextTagVelocity(tt, xvel, yvel)
endfunction
]]>
    </Function>

    <Function Name="ShowTextTagForceBJ" ReturnType="nothing" ArgumentList="boolean show, texttag tt, force whichForce">
      <![CDATA[function ShowTextTagForceBJ takes boolean show, texttag tt, force whichForce returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetTextTagVisibility(tt, show)
    endif
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedTextTag" ReturnType="texttag" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedTextTag takes nothing returns texttag
    return bj_lastCreatedTextTag
endfunction
]]>
    </Function>

    <Function Name="PauseGameOn" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function PauseGameOn takes nothing returns nothing
    call PauseGame(true)
endfunction
]]>
    </Function>

    <Function Name="PauseGameOff" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function PauseGameOff takes nothing returns nothing
    call PauseGame(false)
endfunction
]]>
    </Function>

    <Function Name="SetUserControlForceOn" ReturnType="nothing" ArgumentList="force whichForce">
      <![CDATA[function SetUserControlForceOn takes force whichForce returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call EnableUserControl(true)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetUserControlForceOff" ReturnType="nothing" ArgumentList="force whichForce">
      <![CDATA[function SetUserControlForceOff takes force whichForce returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call EnableUserControl(false)
    endif
endfunction
]]>
    </Function>

    <Function Name="ShowInterfaceForceOn" ReturnType="nothing" ArgumentList="force whichForce, real fadeDuration">
      <![CDATA[function ShowInterfaceForceOn takes force whichForce, real fadeDuration returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ShowInterface(true, fadeDuration)
    endif
endfunction
]]>
    </Function>

    <Function Name="ShowInterfaceForceOff" ReturnType="nothing" ArgumentList="force whichForce, real fadeDuration">
      <![CDATA[function ShowInterfaceForceOff takes force whichForce, real fadeDuration returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ShowInterface(false, fadeDuration)
    endif
endfunction
]]>
    </Function>

    <Function Name="PingMinimapForForce" ReturnType="nothing" ArgumentList="force whichForce, real x, real y, real duration">
      <![CDATA[function PingMinimapForForce takes force whichForce, real x, real y, real duration returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PingMinimap(x, y, duration)
        //call StartSound(bj_pingMinimapSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="PingMinimapLocForForce" ReturnType="nothing" ArgumentList="force whichForce, location loc, real duration">
      <![CDATA[function PingMinimapLocForForce takes force whichForce, location loc, real duration returns nothing
    call PingMinimapForForce(whichForce, GetLocationX(loc), GetLocationY(loc), duration)
endfunction
]]>
    </Function>

    <Function Name="PingMinimapForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, real x, real y, real duration">
      <![CDATA[function PingMinimapForPlayer takes player whichPlayer, real x, real y, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PingMinimap(x, y, duration)
        //call StartSound(bj_pingMinimapSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="PingMinimapLocForPlayer" ReturnType="nothing" ArgumentList="player whichPlayer, location loc, real duration">
      <![CDATA[function PingMinimapLocForPlayer takes player whichPlayer, location loc, real duration returns nothing
    call PingMinimapForPlayer(whichPlayer, GetLocationX(loc), GetLocationY(loc), duration)
endfunction
]]>
    </Function>

    <Function Name="PingMinimapForForceEx" ReturnType="nothing" ArgumentList="force whichForce, real x, real y, real duration, integer style, real red, real green, real blue">
      <![CDATA[function PingMinimapForForceEx takes force whichForce, real x, real y, real duration, integer style, real red, real green, real blue returns nothing
    local integer red255   = PercentTo255(red)
    local integer green255 = PercentTo255(green)
    local integer blue255  = PercentTo255(blue)

    if (IsPlayerInForce(GetLocalPlayer(), whichForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        // Prevent 100% red simple and flashy pings, as they become "attack" pings.
        if (red255 == 255) and (green255 == 0) and (blue255 == 0) then
            set red255 = 254
        endif

        if (style == bj_MINIMAPPINGSTYLE_SIMPLE) then
            call PingMinimapEx(x, y, duration, red255, green255, blue255, false)
        elseif (style == bj_MINIMAPPINGSTYLE_FLASHY) then
            call PingMinimapEx(x, y, duration, red255, green255, blue255, true)
        elseif (style == bj_MINIMAPPINGSTYLE_ATTACK) then
            call PingMinimapEx(x, y, duration, 255, 0, 0, false)
        else
            // Unrecognized ping style - ignore the request.
        endif
        
        //call StartSound(bj_pingMinimapSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="PingMinimapLocForForceEx" ReturnType="nothing" ArgumentList="force whichForce, location loc, real duration, integer style, real red, real green, real blue">
      <![CDATA[function PingMinimapLocForForceEx takes force whichForce, location loc, real duration, integer style, real red, real green, real blue returns nothing
    call PingMinimapForForceEx(whichForce, GetLocationX(loc), GetLocationY(loc), duration, style, red, green, blue)
endfunction
]]>
    </Function>

    <Function Name="EnableWorldFogBoundaryBJ" ReturnType="nothing" ArgumentList="boolean enable, force f">
      <![CDATA[function EnableWorldFogBoundaryBJ takes boolean enable, force f returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), f)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call EnableWorldFogBoundary(enable)
    endif
endfunction
]]>
    </Function>

    <Function Name="EnableOcclusionBJ" ReturnType="nothing" ArgumentList="boolean enable, force f">
      <![CDATA[function EnableOcclusionBJ takes boolean enable, force f returns nothing
    if (IsPlayerInForce(GetLocalPlayer(), f)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call EnableOcclusion(enable)
    endif
endfunction
]]>
    </Function>

    <Function Name="CancelCineSceneBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CancelCineSceneBJ takes nothing returns nothing
    call StopSoundBJ(bj_cineSceneLastSound, true)
    call EndCinematicScene()
endfunction
]]>
    </Function>

    <Function Name="TryInitCinematicBehaviorBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function TryInitCinematicBehaviorBJ takes nothing returns nothing
    local integer index

    if (bj_cineSceneBeingSkipped == null) then
        set bj_cineSceneBeingSkipped = CreateTrigger()
        set index = 0
        loop
            call TriggerRegisterPlayerEvent(bj_cineSceneBeingSkipped, Player(index), EVENT_PLAYER_END_CINEMATIC)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYERS
        endloop
        call TriggerAddAction(bj_cineSceneBeingSkipped, function CancelCineSceneBJ)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetCinematicSceneBJ" ReturnType="nothing" ArgumentList="sound soundHandle, integer portraitUnitId, playercolor color, string speakerTitle, string text, real sceneDuration, real voiceoverDuration">
      <![CDATA[function SetCinematicSceneBJ takes sound soundHandle, integer portraitUnitId, playercolor color, string speakerTitle, string text, real sceneDuration, real voiceoverDuration returns nothing
    set bj_cineSceneLastSound = soundHandle
    call PlaySoundBJ(soundHandle)
    call SetCinematicScene(portraitUnitId, color, speakerTitle, text, sceneDuration, voiceoverDuration)
endfunction
]]>
    </Function>

    <Function Name="GetTransmissionDuration" ReturnType="real" ArgumentList="sound soundHandle, integer timeType, real timeVal">
      <![CDATA[function GetTransmissionDuration takes sound soundHandle, integer timeType, real timeVal returns real
    local real duration

    if (timeType == bj_TIMETYPE_ADD) then
        set duration = GetSoundDurationBJ(soundHandle) + timeVal
    elseif (timeType == bj_TIMETYPE_SET) then
        set duration = timeVal
    elseif (timeType == bj_TIMETYPE_SUB) then
        set duration = GetSoundDurationBJ(soundHandle) - timeVal
    else
        // Unrecognized timeType - ignore timeVal.
        set duration = GetSoundDurationBJ(soundHandle)
    endif

    // Make sure we have a non-negative duration.
    if (duration < 0) then
        set duration = 0
    endif
    return duration
endfunction
]]>
    </Function>

    <Function Name="WaitTransmissionDuration" ReturnType="nothing" ArgumentList="sound soundHandle, integer timeType, real timeVal">
      <![CDATA[function WaitTransmissionDuration takes sound soundHandle, integer timeType, real timeVal returns nothing
    if (timeType == bj_TIMETYPE_SET) then
        // If we have a static duration wait, just perform the wait.
        call TriggerSleepAction(timeVal)

    elseif (soundHandle == null) then
        // If the sound does not exist, perform a default length wait.
        call TriggerSleepAction(bj_NOTHING_SOUND_DURATION)

    elseif (timeType == bj_TIMETYPE_SUB) then
        // If the transmission is cutting off the sound, wait for the sound
        // to be mostly finished.
        call WaitForSoundBJ(soundHandle, timeVal)

    elseif (timeType == bj_TIMETYPE_ADD) then
        // If the transmission is extending beyond the sound's length, wait
        // for it to finish, and then wait the additional time.
        call WaitForSoundBJ(soundHandle, 0)
        call TriggerSleepAction(timeVal)

    else
        // Unrecognized timeType - ignore.
    endif
endfunction
]]>
    </Function>

    <Function Name="DoTransmissionBasicsXYBJ" ReturnType="nothing" ArgumentList="integer unitId, playercolor color, real x, real y, sound soundHandle, string unitName, string message, real duration">
      <![CDATA[function DoTransmissionBasicsXYBJ takes integer unitId, playercolor color, real x, real y, sound soundHandle, string unitName, string message, real duration returns nothing
    call SetCinematicSceneBJ(soundHandle, unitId, color, unitName, message, duration + bj_TRANSMISSION_PORT_HANGTIME, duration)

    if (unitId != 0) then
        call PingMinimap(x, y, bj_TRANSMISSION_PING_TIME)
        //call SetCameraQuickPosition(x, y)
    endif
endfunction
]]>
    </Function>

    <Function Name="TransmissionFromUnitWithNameBJ" ReturnType="nothing" ArgumentList="force toForce, unit whichUnit, string unitName, sound soundHandle, string message, integer timeType, real timeVal, boolean wait">
      <![CDATA[function TransmissionFromUnitWithNameBJ takes force toForce, unit whichUnit, string unitName, sound soundHandle, string message, integer timeType, real timeVal, boolean wait returns nothing
    call TryInitCinematicBehaviorBJ()

    // Ensure that the time value is non-negative.
    set timeVal = RMaxBJ(timeVal, 0)

    set bj_lastTransmissionDuration = GetTransmissionDuration(soundHandle, timeType, timeVal)
    set bj_lastPlayedSound = soundHandle

    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        if (whichUnit == null) then
            // If the unit reference is invalid, send the transmission from the center of the map with no portrait.
            call DoTransmissionBasicsXYBJ(0, PLAYER_COLOR_RED, 0, 0, soundHandle, unitName, message, bj_lastTransmissionDuration)
        else
            call DoTransmissionBasicsXYBJ(GetUnitTypeId(whichUnit), GetPlayerColor(GetOwningPlayer(whichUnit)), GetUnitX(whichUnit), GetUnitY(whichUnit), soundHandle, unitName, message, bj_lastTransmissionDuration)
            if (not IsUnitHidden(whichUnit)) then
                call UnitAddIndicator(whichUnit, bj_TRANSMISSION_IND_RED, bj_TRANSMISSION_IND_BLUE, bj_TRANSMISSION_IND_GREEN, bj_TRANSMISSION_IND_ALPHA)
            endif
        endif
    endif

    if wait and (bj_lastTransmissionDuration > 0) then
        // call TriggerSleepAction(bj_lastTransmissionDuration)
        call WaitTransmissionDuration(soundHandle, timeType, timeVal)
    endif

endfunction
]]>
    </Function>

    <Function Name="TransmissionFromUnitTypeWithNameBJ" ReturnType="nothing" ArgumentList="force toForce, player fromPlayer, integer unitId, string unitName, location loc, sound soundHandle, string message, integer timeType, real timeVal, boolean wait">
      <![CDATA[function TransmissionFromUnitTypeWithNameBJ takes force toForce, player fromPlayer, integer unitId, string unitName, location loc, sound soundHandle, string message, integer timeType, real timeVal, boolean wait returns nothing
    call TryInitCinematicBehaviorBJ()

    // Ensure that the time value is non-negative.
    set timeVal = RMaxBJ(timeVal, 0)

    set bj_lastTransmissionDuration = GetTransmissionDuration(soundHandle, timeType, timeVal)
    set bj_lastPlayedSound = soundHandle

    if (IsPlayerInForce(GetLocalPlayer(), toForce)) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        call DoTransmissionBasicsXYBJ(unitId, GetPlayerColor(fromPlayer), GetLocationX(loc), GetLocationY(loc), soundHandle, unitName, message, bj_lastTransmissionDuration)
    endif

    if wait and (bj_lastTransmissionDuration > 0) then
        // call TriggerSleepAction(bj_lastTransmissionDuration)
        call WaitTransmissionDuration(soundHandle, timeType, timeVal)
    endif

endfunction
]]>
    </Function>

    <Function Name="GetLastTransmissionDurationBJ" ReturnType="real" ArgumentList="nothing">
      <![CDATA[function GetLastTransmissionDurationBJ takes nothing returns real
    return bj_lastTransmissionDuration
endfunction
]]>
    </Function>

    <Function Name="ForceCinematicSubtitlesBJ" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[function ForceCinematicSubtitlesBJ takes boolean flag returns nothing
    call ForceCinematicSubtitles(flag)
endfunction
]]>
    </Function>

    <Function Name="CinematicModeExBJ" ReturnType="nothing" ArgumentList="boolean cineMode, force forForce, real interfaceFadeTime">
      <![CDATA[function CinematicModeExBJ takes boolean cineMode, force forForce, real interfaceFadeTime returns nothing
    // If the game hasn't started yet, perform interface fades immediately
    if (not bj_gameStarted) then
        set interfaceFadeTime = 0
    endif

    if (cineMode) then
        // Save the UI state so that we can restore it later.
        if (not bj_cineModeAlreadyIn) then
            set bj_cineModeAlreadyIn = true
            set bj_cineModePriorSpeed = GetGameSpeed()
            set bj_cineModePriorFogSetting = IsFogEnabled()
            set bj_cineModePriorMaskSetting = IsFogMaskEnabled()
            set bj_cineModePriorDawnDusk = IsDawnDuskEnabled()
            set bj_cineModeSavedSeed = GetRandomInt(0, 1000000)
        endif

        // Perform local changes
        if (IsPlayerInForce(GetLocalPlayer(), forForce)) then
            // Use only local code (no net traffic) within this block to avoid desyncs.
            call ClearTextMessages()
            call ShowInterface(false, interfaceFadeTime)
            call EnableUserControl(false)
            call EnableOcclusion(false)
            call SetCineModeVolumeGroupsBJ()
        endif

        // Perform global changes
        call SetGameSpeed(bj_CINEMODE_GAMESPEED)
        call SetMapFlag(MAP_LOCK_SPEED, true)
        call FogMaskEnable(false)
        call FogEnable(false)
        call EnableWorldFogBoundary(false)
        call EnableDawnDusk(false)

        // Use a fixed random seed, so that cinematics play consistently.
        call SetRandomSeed(0)
    else
        set bj_cineModeAlreadyIn = false

        // Perform local changes
        if (IsPlayerInForce(GetLocalPlayer(), forForce)) then
            // Use only local code (no net traffic) within this block to avoid desyncs.
            call ShowInterface(true, interfaceFadeTime)
            call EnableUserControl(true)
            call EnableOcclusion(true)
            call VolumeGroupReset()
            call EndThematicMusic()
            call CameraResetSmoothingFactorBJ()
        endif

        // Perform global changes
        call SetMapFlag(MAP_LOCK_SPEED, false)
        call SetGameSpeed(bj_cineModePriorSpeed)
        call FogMaskEnable(bj_cineModePriorMaskSetting)
        call FogEnable(bj_cineModePriorFogSetting)
        call EnableWorldFogBoundary(true)
        call EnableDawnDusk(bj_cineModePriorDawnDusk)
        call SetRandomSeed(bj_cineModeSavedSeed)
    endif
endfunction
]]>
    </Function>

    <Function Name="CinematicModeBJ" ReturnType="nothing" ArgumentList="boolean cineMode, force forForce">
      <![CDATA[function CinematicModeBJ takes boolean cineMode, force forForce returns nothing
    call CinematicModeExBJ(cineMode, forForce, bj_CINEMODE_INTERFACEFADE)
endfunction
]]>
    </Function>

    <Function Name="DisplayCineFilterBJ" ReturnType="nothing" ArgumentList="boolean flag">
      <![CDATA[function DisplayCineFilterBJ takes boolean flag returns nothing
    call DisplayCineFilter(flag)
endfunction
]]>
    </Function>

    <Function Name="CinematicFadeCommonBJ" ReturnType="nothing" ArgumentList="real red, real green, real blue, real duration, string tex, real startTrans, real endTrans">
      <![CDATA[function CinematicFadeCommonBJ takes real red, real green, real blue, real duration, string tex, real startTrans, real endTrans returns nothing
    if (duration == 0) then
        // If the fade is instant, use the same starting and ending values,
        // so that we effectively do a set rather than a fade.
        set startTrans = endTrans
    endif
    call EnableUserUI(false)
    call SetCineFilterTexture(tex)
    call SetCineFilterBlendMode(BLEND_MODE_BLEND)
    call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
    call SetCineFilterStartUV(0, 0, 1, 1)
    call SetCineFilterEndUV(0, 0, 1, 1)
    call SetCineFilterStartColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100-startTrans))
    call SetCineFilterEndColor(PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100-endTrans))
    call SetCineFilterDuration(duration)
    call DisplayCineFilter(true)
endfunction
]]>
    </Function>

    <Function Name="FinishCinematicFadeBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function FinishCinematicFadeBJ takes nothing returns nothing
    call DestroyTimer(bj_cineFadeFinishTimer)
    set bj_cineFadeFinishTimer = null
    call DisplayCineFilter(false)
    call EnableUserUI(true)
endfunction
]]>
    </Function>

    <Function Name="FinishCinematicFadeAfterBJ" ReturnType="nothing" ArgumentList="real duration">
      <![CDATA[function FinishCinematicFadeAfterBJ takes real duration returns nothing
    // Create a timer to end the cinematic fade.
    set bj_cineFadeFinishTimer = CreateTimer()
    call TimerStart(bj_cineFadeFinishTimer, duration, false, function FinishCinematicFadeBJ)
endfunction
]]>
    </Function>

    <Function Name="ContinueCinematicFadeBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function ContinueCinematicFadeBJ takes nothing returns nothing
    call DestroyTimer(bj_cineFadeContinueTimer)
    set bj_cineFadeContinueTimer = null
    call CinematicFadeCommonBJ(bj_cineFadeContinueRed, bj_cineFadeContinueGreen, bj_cineFadeContinueBlue, bj_cineFadeContinueDuration, bj_cineFadeContinueTex, bj_cineFadeContinueTrans, 100)
endfunction
]]>
    </Function>

    <Function Name="ContinueCinematicFadeAfterBJ" ReturnType="nothing" ArgumentList="real duration, real red, real green, real blue, real trans, string tex">
      <![CDATA[function ContinueCinematicFadeAfterBJ takes real duration, real red, real green, real blue, real trans, string tex returns nothing
    set bj_cineFadeContinueRed = red
    set bj_cineFadeContinueGreen = green
    set bj_cineFadeContinueBlue = blue
    set bj_cineFadeContinueTrans = trans
    set bj_cineFadeContinueDuration = duration
    set bj_cineFadeContinueTex = tex

    // Create a timer to continue the cinematic fade.
    set bj_cineFadeContinueTimer = CreateTimer()
    call TimerStart(bj_cineFadeContinueTimer, duration, false, function ContinueCinematicFadeBJ)
endfunction
]]>
    </Function>

    <Function Name="AbortCinematicFadeBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function AbortCinematicFadeBJ takes nothing returns nothing
    if (bj_cineFadeContinueTimer != null) then
        call DestroyTimer(bj_cineFadeContinueTimer)
    endif

    if (bj_cineFadeFinishTimer != null) then
        call DestroyTimer(bj_cineFadeFinishTimer)
    endif
endfunction
]]>
    </Function>

    <Function Name="CinematicFadeBJ" ReturnType="nothing" ArgumentList="integer fadetype, real duration, string tex, real red, real green, real blue, real trans">
      <![CDATA[function CinematicFadeBJ takes integer fadetype, real duration, string tex, real red, real green, real blue, real trans returns nothing
    if (fadetype == bj_CINEFADETYPE_FADEOUT) then
        // Fade out to the requested color.
        call AbortCinematicFadeBJ()
        call CinematicFadeCommonBJ(red, green, blue, duration, tex, 100, trans)
    elseif (fadetype == bj_CINEFADETYPE_FADEIN) then
        // Fade in from the requested color.
        call AbortCinematicFadeBJ()
        call CinematicFadeCommonBJ(red, green, blue, duration, tex, trans, 100)
        call FinishCinematicFadeAfterBJ(duration)
    elseif (fadetype == bj_CINEFADETYPE_FADEOUTIN) then
        // Fade out to the requested color, and then fade back in from it.
        if (duration > 0) then
            call AbortCinematicFadeBJ()
            call CinematicFadeCommonBJ(red, green, blue, duration * 0.5, tex, 100, trans)
            call ContinueCinematicFadeAfterBJ(duration * 0.5, red, green, blue, trans, tex)
            call FinishCinematicFadeAfterBJ(duration)
        endif
    else
        // Unrecognized fadetype - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="CinematicFilterGenericBJ" ReturnType="nothing" ArgumentList="real duration, blendmode bmode, string tex, real red0, real green0, real blue0, real trans0, real red1, real green1, real blue1, real trans1">
      <![CDATA[function CinematicFilterGenericBJ takes real duration, blendmode bmode, string tex, real red0, real green0, real blue0, real trans0, real red1, real green1, real blue1, real trans1 returns nothing
    call AbortCinematicFadeBJ()
    call SetCineFilterTexture(tex)
    call SetCineFilterBlendMode(bmode)
    call SetCineFilterTexMapFlags(TEXMAP_FLAG_NONE)
    call SetCineFilterStartUV(0, 0, 1, 1)
    call SetCineFilterEndUV(0, 0, 1, 1)
    call SetCineFilterStartColor(PercentTo255(red0), PercentTo255(green0), PercentTo255(blue0), PercentTo255(100-trans0))
    call SetCineFilterEndColor(PercentTo255(red1), PercentTo255(green1), PercentTo255(blue1), PercentTo255(100-trans1))
    call SetCineFilterDuration(duration)
    call DisplayCineFilter(true)
endfunction
]]>
    </Function>

    <Function Name="RescueUnitBJ" ReturnType="nothing" ArgumentList="unit whichUnit, player rescuer, boolean changeColor">
      <![CDATA[function RescueUnitBJ takes unit whichUnit, player rescuer, boolean changeColor returns nothing
    if IsUnitDeadBJ(whichUnit) or (GetOwningPlayer(whichUnit) == rescuer) then
        return
    endif

    call StartSound(bj_rescueSound)
    call SetUnitOwner(whichUnit, rescuer, changeColor)
    call UnitAddIndicator(whichUnit, 0, 255, 0, 255)
    call PingMinimapForPlayer(rescuer, GetUnitX(whichUnit), GetUnitY(whichUnit), bj_RESCUE_PING_TIME)
endfunction
]]>
    </Function>

    <Function Name="TriggerActionUnitRescuedBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function TriggerActionUnitRescuedBJ takes nothing returns nothing
    local unit theUnit = GetTriggerUnit()

    if IsUnitType(theUnit, UNIT_TYPE_STRUCTURE) then
        call RescueUnitBJ(theUnit, GetOwningPlayer(GetRescuer()), bj_rescueChangeColorBldg)
    else
        call RescueUnitBJ(theUnit, GetOwningPlayer(GetRescuer()), bj_rescueChangeColorUnit)
    endif
endfunction
]]>
    </Function>

    <Function Name="TryInitRescuableTriggersBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function TryInitRescuableTriggersBJ takes nothing returns nothing
    local integer index

    if (bj_rescueUnitBehavior == null) then
        set bj_rescueUnitBehavior = CreateTrigger()
        set index = 0
        loop
            call TriggerRegisterPlayerUnitEvent(bj_rescueUnitBehavior, Player(index), EVENT_PLAYER_UNIT_RESCUED, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddAction(bj_rescueUnitBehavior, function TriggerActionUnitRescuedBJ)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetRescueUnitColorChangeBJ" ReturnType="nothing" ArgumentList="boolean changeColor">
      <![CDATA[function SetRescueUnitColorChangeBJ takes boolean changeColor returns nothing
    set bj_rescueChangeColorUnit = changeColor
endfunction
]]>
    </Function>

    <Function Name="SetRescueBuildingColorChangeBJ" ReturnType="nothing" ArgumentList="boolean changeColor">
      <![CDATA[function SetRescueBuildingColorChangeBJ takes boolean changeColor returns nothing
    set bj_rescueChangeColorBldg = changeColor
endfunction
]]>
    </Function>

    <Function Name="MakeUnitRescuableToForceBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MakeUnitRescuableToForceBJEnum takes nothing returns nothing
    call TryInitRescuableTriggersBJ()
    call SetUnitRescuable(bj_makeUnitRescuableUnit, GetEnumPlayer(), bj_makeUnitRescuableFlag)
endfunction
]]>
    </Function>

    <Function Name="MakeUnitRescuableToForceBJ" ReturnType="nothing" ArgumentList="unit whichUnit, boolean isRescuable, force whichForce">
      <![CDATA[function MakeUnitRescuableToForceBJ takes unit whichUnit, boolean isRescuable, force whichForce returns nothing
    // Flag the unit as rescuable/unrescuable for the appropriate players.
    set bj_makeUnitRescuableUnit = whichUnit
    set bj_makeUnitRescuableFlag = isRescuable
    call ForForce(whichForce, function MakeUnitRescuableToForceBJEnum)
endfunction
]]>
    </Function>

    <Function Name="InitRescuableBehaviorBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitRescuableBehaviorBJ takes nothing returns nothing
    local integer index

    set index = 0
    loop
        // If at least one player slot is "Rescuable"-controlled, init the
        // rescue behavior triggers.
        if (GetPlayerController(Player(index)) == MAP_CONTROL_RESCUABLE) then
            call TryInitRescuableTriggersBJ()
            return
        endif
        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="SetPlayerTechResearchedSwap" ReturnType="nothing" ArgumentList="integer techid, integer levels, player whichPlayer">
      <![CDATA[function SetPlayerTechResearchedSwap takes integer techid, integer levels, player whichPlayer returns nothing
    call SetPlayerTechResearched(whichPlayer, techid, levels)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerTechMaxAllowedSwap" ReturnType="nothing" ArgumentList="integer techid, integer maximum, player whichPlayer">
      <![CDATA[function SetPlayerTechMaxAllowedSwap takes integer techid, integer maximum, player whichPlayer returns nothing
    call SetPlayerTechMaxAllowed(whichPlayer, techid, maximum)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerMaxHeroesAllowed" ReturnType="nothing" ArgumentList="integer maximum, player whichPlayer">
      <![CDATA[function SetPlayerMaxHeroesAllowed takes integer maximum, player whichPlayer returns nothing
    call SetPlayerTechMaxAllowed(whichPlayer, 'HERO', maximum)
endfunction
]]>
    </Function>

    <Function Name="GetPlayerTechCountSimple" ReturnType="integer" ArgumentList="integer techid, player whichPlayer">
      <![CDATA[function GetPlayerTechCountSimple takes integer techid, player whichPlayer returns integer
    return GetPlayerTechCount(whichPlayer, techid, true)
endfunction
]]>
    </Function>

    <Function Name="GetPlayerTechMaxAllowedSwap" ReturnType="integer" ArgumentList="integer techid, player whichPlayer">
      <![CDATA[function GetPlayerTechMaxAllowedSwap takes integer techid, player whichPlayer returns integer
    return GetPlayerTechMaxAllowed(whichPlayer, techid)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerAbilityAvailableBJ" ReturnType="nothing" ArgumentList="boolean avail, integer abilid, player whichPlayer">
      <![CDATA[function SetPlayerAbilityAvailableBJ takes boolean avail, integer abilid, player whichPlayer returns nothing
    call SetPlayerAbilityAvailable(whichPlayer, abilid, avail)
endfunction
]]>
    </Function>

    <Function Name="SetCampaignMenuRaceBJ" ReturnType="nothing" ArgumentList="integer campaignNumber">
      <![CDATA[function SetCampaignMenuRaceBJ takes integer campaignNumber returns nothing
    if (campaignNumber == bj_CAMPAIGN_INDEX_T) then
        call SetCampaignMenuRace(RACE_OTHER)
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_H) then
        call SetCampaignMenuRace(RACE_HUMAN)
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_U) then
        call SetCampaignMenuRace(RACE_UNDEAD)
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_O) then
        call SetCampaignMenuRace(RACE_ORC)
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_N) then
        call SetCampaignMenuRace(RACE_NIGHTELF)
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_XN) then
        call SetCampaignMenuRaceEx(bj_CAMPAIGN_OFFSET_XN)
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_XH) then
        call SetCampaignMenuRaceEx(bj_CAMPAIGN_OFFSET_XH)
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_XU) then
        call SetCampaignMenuRaceEx(bj_CAMPAIGN_OFFSET_XU)
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_XO) then
        call SetCampaignMenuRaceEx(bj_CAMPAIGN_OFFSET_XO)
    else
        // Unrecognized campaign - ignore the request
    endif
endfunction
]]>
    </Function>

    <Function Name="SetMissionAvailableBJ" ReturnType="nothing" ArgumentList="boolean available, integer missionIndex">
      <![CDATA[function SetMissionAvailableBJ takes boolean available, integer missionIndex returns nothing
    local integer campaignNumber = missionIndex / 1000
    local integer missionNumber = missionIndex - campaignNumber * 1000

    call SetMissionAvailable(campaignNumber, missionNumber, available)
endfunction
]]>
    </Function>

    <Function Name="SetCampaignAvailableBJ" ReturnType="nothing" ArgumentList="boolean available, integer campaignNumber">
      <![CDATA[function SetCampaignAvailableBJ takes boolean available, integer campaignNumber returns nothing
    local integer campaignOffset

    if (campaignNumber == bj_CAMPAIGN_INDEX_H) then
        call SetTutorialCleared(true)
    endif

    if (campaignNumber == bj_CAMPAIGN_INDEX_XN) then
        set campaignOffset = bj_CAMPAIGN_OFFSET_XN
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_XH) then
        set campaignOffset = bj_CAMPAIGN_OFFSET_XH
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_XU) then
        set campaignOffset = bj_CAMPAIGN_OFFSET_XU
    elseif (campaignNumber == bj_CAMPAIGN_INDEX_XO) then
        set campaignOffset = bj_CAMPAIGN_OFFSET_XO
    else
        set campaignOffset = campaignNumber
    endif

    call SetCampaignAvailable(campaignOffset, available)
    call SetCampaignMenuRaceBJ(campaignNumber)
    call ForceCampaignSelectScreen()
endfunction
]]>
    </Function>

    <Function Name="SetCinematicAvailableBJ" ReturnType="nothing" ArgumentList="boolean available, integer cinematicIndex">
      <![CDATA[function SetCinematicAvailableBJ takes boolean available, integer cinematicIndex returns nothing
    if ( cinematicIndex == bj_CINEMATICINDEX_TOP ) then
        call SetOpCinematicAvailable( bj_CAMPAIGN_INDEX_T, available )
        call PlayCinematic( "TutorialOp" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_HOP) then
        call SetOpCinematicAvailable( bj_CAMPAIGN_INDEX_H, available )
        call PlayCinematic( "HumanOp" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_HED) then
        call SetEdCinematicAvailable( bj_CAMPAIGN_INDEX_H, available )
        call PlayCinematic( "HumanEd" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_OOP) then
        call SetOpCinematicAvailable( bj_CAMPAIGN_INDEX_O, available )
        call PlayCinematic( "OrcOp" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_OED) then
        call SetEdCinematicAvailable( bj_CAMPAIGN_INDEX_O, available )
        call PlayCinematic( "OrcEd" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_UOP) then
        call SetEdCinematicAvailable( bj_CAMPAIGN_INDEX_U, available )
        call PlayCinematic( "UndeadOp" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_UED) then
        call SetEdCinematicAvailable( bj_CAMPAIGN_INDEX_U, available )
        call PlayCinematic( "UndeadEd" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_NOP) then
        call SetEdCinematicAvailable( bj_CAMPAIGN_INDEX_N, available )
        call PlayCinematic( "NightElfOp" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_NED) then
        call SetEdCinematicAvailable( bj_CAMPAIGN_INDEX_N, available )
        call PlayCinematic( "NightElfEd" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_XOP) then
        call SetOpCinematicAvailable( bj_CAMPAIGN_OFFSET_XN, available )
        call PlayCinematic( "IntroX" )
    elseif (cinematicIndex == bj_CINEMATICINDEX_XED) then
        call SetEdCinematicAvailable( bj_CAMPAIGN_OFFSET_XU, available )
        call PlayCinematic( "OutroX" )
    else
        // Unrecognized cinematic - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="InitGameCacheBJ" ReturnType="gamecache" ArgumentList="string campaignFile">
      <![CDATA[function InitGameCacheBJ takes string campaignFile returns gamecache
    set bj_lastCreatedGameCache = InitGameCache(campaignFile)
    return bj_lastCreatedGameCache
endfunction
]]>
    </Function>

    <Function Name="SaveGameCacheBJ" ReturnType="boolean" ArgumentList="gamecache cache">
      <![CDATA[function SaveGameCacheBJ takes gamecache cache returns boolean
    return SaveGameCache(cache)
endfunction
]]>
    </Function>

    <Function Name="GetLastCreatedGameCacheBJ" ReturnType="gamecache" ArgumentList="nothing">
      <![CDATA[function GetLastCreatedGameCacheBJ takes nothing returns gamecache
    return bj_lastCreatedGameCache
endfunction
]]>
    </Function>

    <Function Name="StoreRealBJ" ReturnType="nothing" ArgumentList="real value, string key, string missionKey, gamecache cache">
      <![CDATA[function StoreRealBJ takes real value, string key, string missionKey, gamecache cache returns nothing
    call StoreReal(cache, missionKey, key, value)
endfunction
]]>
    </Function>

    <Function Name="StoreIntegerBJ" ReturnType="nothing" ArgumentList="integer value, string key, string missionKey, gamecache cache">
      <![CDATA[function StoreIntegerBJ takes integer value, string key, string missionKey, gamecache cache returns nothing
    call StoreInteger(cache, missionKey, key, value)
endfunction
]]>
    </Function>

    <Function Name="StoreBooleanBJ" ReturnType="nothing" ArgumentList="boolean value, string key, string missionKey, gamecache cache">
      <![CDATA[function StoreBooleanBJ takes boolean value, string key, string missionKey, gamecache cache returns nothing
    call StoreBoolean(cache, missionKey, key, value)
endfunction
]]>
    </Function>

    <Function Name="StoreStringBJ" ReturnType="boolean" ArgumentList="string value, string key, string missionKey, gamecache cache">
      <![CDATA[function StoreStringBJ takes string value, string key, string missionKey, gamecache cache returns boolean
    return StoreString(cache, missionKey, key, value)
endfunction
]]>
    </Function>

    <Function Name="StoreUnitBJ" ReturnType="boolean" ArgumentList="unit whichUnit, string key, string missionKey, gamecache cache">
      <![CDATA[function StoreUnitBJ takes unit whichUnit, string key, string missionKey, gamecache cache returns boolean
    return StoreUnit(cache, missionKey, key, whichUnit)
endfunction
]]>
    </Function>

    <Function Name="GetStoredRealBJ" ReturnType="real" ArgumentList="string key, string missionKey, gamecache cache">
      <![CDATA[function GetStoredRealBJ takes string key, string missionKey, gamecache cache returns real
    //call SyncStoredReal(cache, missionKey, key)
    return GetStoredReal(cache, missionKey, key)
endfunction
]]>
    </Function>

    <Function Name="GetStoredIntegerBJ" ReturnType="integer" ArgumentList="string key, string missionKey, gamecache cache">
      <![CDATA[function GetStoredIntegerBJ takes string key, string missionKey, gamecache cache returns integer
    //call SyncStoredInteger(cache, missionKey, key)
    return GetStoredInteger(cache, missionKey, key)
endfunction
]]>
    </Function>

    <Function Name="GetStoredBooleanBJ" ReturnType="boolean" ArgumentList="string key, string missionKey, gamecache cache">
      <![CDATA[function GetStoredBooleanBJ takes string key, string missionKey, gamecache cache returns boolean
    //call SyncStoredBoolean(cache, missionKey, key)
    return GetStoredBoolean(cache, missionKey, key)
endfunction
]]>
    </Function>

    <Function Name="GetStoredStringBJ" ReturnType="string" ArgumentList="string key, string missionKey, gamecache cache">
      <![CDATA[function GetStoredStringBJ takes string key, string missionKey, gamecache cache returns string
    local string s

    //call SyncStoredString(cache, missionKey, key)
    set s = GetStoredString(cache, missionKey, key)
    if (s == null) then
        return ""
    else
        return s
    endif
endfunction
]]>
    </Function>

    <Function Name="RestoreUnitLocFacingAngleBJ" ReturnType="unit" ArgumentList="string key, string missionKey, gamecache cache, player forWhichPlayer, location loc, real facing">
      <![CDATA[function RestoreUnitLocFacingAngleBJ takes string key, string missionKey, gamecache cache, player forWhichPlayer, location loc, real facing returns unit
    //call SyncStoredUnit(cache, missionKey, key)
    set bj_lastLoadedUnit = RestoreUnit(cache, missionKey, key, forWhichPlayer, GetLocationX(loc), GetLocationY(loc), facing)
    return bj_lastLoadedUnit
endfunction
]]>
    </Function>

    <Function Name="RestoreUnitLocFacingPointBJ" ReturnType="unit" ArgumentList="string key, string missionKey, gamecache cache, player forWhichPlayer, location loc, location lookAt">
      <![CDATA[function RestoreUnitLocFacingPointBJ takes string key, string missionKey, gamecache cache, player forWhichPlayer, location loc, location lookAt returns unit
    //call SyncStoredUnit(cache, missionKey, key)
    return RestoreUnitLocFacingAngleBJ(key, missionKey, cache, forWhichPlayer, loc, AngleBetweenPoints(loc, lookAt))
endfunction
]]>
    </Function>

    <Function Name="GetLastRestoredUnitBJ" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[function GetLastRestoredUnitBJ takes nothing returns unit
    return bj_lastLoadedUnit
endfunction
]]>
    </Function>

    <Function Name="FlushGameCacheBJ" ReturnType="nothing" ArgumentList="gamecache cache">
      <![CDATA[function FlushGameCacheBJ takes gamecache cache returns nothing
    call FlushGameCache(cache)
endfunction
]]>
    </Function>

    <Function Name="FlushStoredMissionBJ" ReturnType="nothing" ArgumentList="string missionKey, gamecache cache">
      <![CDATA[function FlushStoredMissionBJ takes string missionKey, gamecache cache returns nothing
    call FlushStoredMission(cache, missionKey)
endfunction
]]>
    </Function>

    <Function Name="HaveStoredValue" ReturnType="boolean" ArgumentList="string key, integer valueType, string missionKey, gamecache cache">
      <![CDATA[function HaveStoredValue takes string key, integer valueType, string missionKey, gamecache cache returns boolean
    if (valueType == bj_GAMECACHE_BOOLEAN) then
        return HaveStoredBoolean(cache, missionKey, key)
    elseif (valueType == bj_GAMECACHE_INTEGER) then
        return HaveStoredInteger(cache, missionKey, key)
    elseif (valueType == bj_GAMECACHE_REAL) then
        return HaveStoredReal(cache, missionKey, key)
    elseif (valueType == bj_GAMECACHE_UNIT) then
        return HaveStoredUnit(cache, missionKey, key)
    elseif (valueType == bj_GAMECACHE_STRING) then
        return HaveStoredString(cache, missionKey, key)
    else
        // Unrecognized value type - ignore the request.
        return false
    endif
endfunction
]]>
    </Function>

    <Function Name="ShowCustomCampaignButton" ReturnType="nothing" ArgumentList="boolean show, integer whichButton">
      <![CDATA[function ShowCustomCampaignButton takes boolean show, integer whichButton returns nothing
    call SetCustomCampaignButtonVisible(whichButton - 1, show)
endfunction
]]>
    </Function>

    <Function Name="IsCustomCampaignButtonVisibile" ReturnType="boolean" ArgumentList="integer whichButton">
      <![CDATA[function IsCustomCampaignButtonVisibile takes integer whichButton returns boolean
    return GetCustomCampaignButtonVisible(whichButton - 1)
endfunction
]]>
    </Function>

    <Function Name="LoadGameBJ" ReturnType="nothing" ArgumentList="string loadFileName, boolean doScoreScreen">
      <![CDATA[function LoadGameBJ takes string loadFileName, boolean doScoreScreen returns nothing
    call LoadGame(loadFileName, doScoreScreen)
endfunction
]]>
    </Function>

    <Function Name="SaveAndChangeLevelBJ" ReturnType="nothing" ArgumentList="string saveFileName, string newLevel, boolean doScoreScreen">
      <![CDATA[function SaveAndChangeLevelBJ takes string saveFileName, string newLevel, boolean doScoreScreen returns nothing
    call SaveGame(saveFileName)
    call ChangeLevel(newLevel, doScoreScreen)
endfunction
]]>
    </Function>

    <Function Name="SaveAndLoadGameBJ" ReturnType="nothing" ArgumentList="string saveFileName, string loadFileName, boolean doScoreScreen">
      <![CDATA[function SaveAndLoadGameBJ takes string saveFileName, string loadFileName, boolean doScoreScreen returns nothing
    call SaveGame(saveFileName)
    call LoadGame(loadFileName, doScoreScreen)
endfunction
]]>
    </Function>

    <Function Name="RenameSaveDirectoryBJ" ReturnType="boolean" ArgumentList="string sourceDirName, string destDirName">
      <![CDATA[function RenameSaveDirectoryBJ takes string sourceDirName, string destDirName returns boolean
    return RenameSaveDirectory(sourceDirName, destDirName)
endfunction
]]>
    </Function>

    <Function Name="RemoveSaveDirectoryBJ" ReturnType="boolean" ArgumentList="string sourceDirName">
      <![CDATA[function RemoveSaveDirectoryBJ takes string sourceDirName returns boolean
    return RemoveSaveDirectory(sourceDirName)
endfunction
]]>
    </Function>

    <Function Name="CopySaveGameBJ" ReturnType="boolean" ArgumentList="string sourceSaveName, string destSaveName">
      <![CDATA[function CopySaveGameBJ takes string sourceSaveName, string destSaveName returns boolean
    return CopySaveGame(sourceSaveName, destSaveName)
endfunction
]]>
    </Function>

    <Function Name="GetPlayerStartLocationX" ReturnType="real" ArgumentList="player whichPlayer">
      <![CDATA[function GetPlayerStartLocationX takes player whichPlayer returns real
    return GetStartLocationX(GetPlayerStartLocation(whichPlayer))
endfunction
]]>
    </Function>

    <Function Name="GetPlayerStartLocationY" ReturnType="real" ArgumentList="player whichPlayer">
      <![CDATA[function GetPlayerStartLocationY takes player whichPlayer returns real
    return GetStartLocationY(GetPlayerStartLocation(whichPlayer))
endfunction
]]>
    </Function>

    <Function Name="GetPlayerStartLocationLoc" ReturnType="location" ArgumentList="player whichPlayer">
      <![CDATA[function GetPlayerStartLocationLoc takes player whichPlayer returns location
    return GetStartLocationLoc(GetPlayerStartLocation(whichPlayer))
endfunction
]]>
    </Function>

    <Function Name="GetRectCenter" ReturnType="location" ArgumentList="rect whichRect">
      <![CDATA[function GetRectCenter takes rect whichRect returns location
    return Location(GetRectCenterX(whichRect), GetRectCenterY(whichRect))
endfunction
]]>
    </Function>

    <Function Name="IsPlayerSlotState" ReturnType="boolean" ArgumentList="player whichPlayer, playerslotstate whichState">
      <![CDATA[function IsPlayerSlotState takes player whichPlayer, playerslotstate whichState returns boolean
    return GetPlayerSlotState(whichPlayer) == whichState
endfunction
]]>
    </Function>

    <Function Name="GetFadeFromSeconds" ReturnType="integer" ArgumentList="real seconds">
      <![CDATA[function GetFadeFromSeconds takes real seconds returns integer
    if (seconds != 0) then
        return 128 / seconds
    else
        return 10000
    endif
endfunction
]]>
    </Function>

    <Function Name="AdjustPlayerStateSimpleBJ" ReturnType="nothing" ArgumentList="player whichPlayer, playerstate whichPlayerState, integer delta">
      <![CDATA[function AdjustPlayerStateSimpleBJ takes player whichPlayer, playerstate whichPlayerState, integer delta returns nothing
    call SetPlayerState(whichPlayer, whichPlayerState, GetPlayerState(whichPlayer, whichPlayerState) + delta)
endfunction
]]>
    </Function>

    <Function Name="AdjustPlayerStateBJ" ReturnType="nothing" ArgumentList="integer delta, player whichPlayer, playerstate whichPlayerState">
      <![CDATA[function AdjustPlayerStateBJ takes integer delta, player whichPlayer, playerstate whichPlayerState returns nothing
    // If the change was positive, apply the difference to the player's
    // gathered resources property as well.
    if (delta > 0) then
        if (whichPlayerState == PLAYER_STATE_RESOURCE_GOLD) then
            call AdjustPlayerStateSimpleBJ(whichPlayer, PLAYER_STATE_GOLD_GATHERED, delta)
        elseif (whichPlayerState == PLAYER_STATE_RESOURCE_LUMBER) then
            call AdjustPlayerStateSimpleBJ(whichPlayer, PLAYER_STATE_LUMBER_GATHERED, delta)
        endif
    endif

    call AdjustPlayerStateSimpleBJ(whichPlayer, whichPlayerState, delta)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerStateBJ" ReturnType="nothing" ArgumentList="player whichPlayer, playerstate whichPlayerState, integer value">
      <![CDATA[function SetPlayerStateBJ takes player whichPlayer, playerstate whichPlayerState, integer value returns nothing
    local integer oldValue = GetPlayerState(whichPlayer, whichPlayerState)
    call AdjustPlayerStateBJ(value - oldValue, whichPlayer, whichPlayerState)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerFlagBJ" ReturnType="nothing" ArgumentList="playerstate whichPlayerFlag, boolean flag, player whichPlayer">
      <![CDATA[function SetPlayerFlagBJ takes playerstate whichPlayerFlag, boolean flag, player whichPlayer returns nothing
    call SetPlayerState(whichPlayer, whichPlayerFlag, IntegerTertiaryOp(flag, 1, 0))
endfunction
]]>
    </Function>

    <Function Name="IsPlayerFlagSetBJ" ReturnType="boolean" ArgumentList="playerstate whichPlayerFlag, player whichPlayer">
      <![CDATA[function IsPlayerFlagSetBJ takes playerstate whichPlayerFlag, player whichPlayer returns boolean
    return GetPlayerState(whichPlayer, whichPlayerFlag) == 1
endfunction
]]>
    </Function>

    <Function Name="AddResourceAmountBJ" ReturnType="nothing" ArgumentList="integer delta, unit whichUnit">
      <![CDATA[function AddResourceAmountBJ takes integer delta, unit whichUnit returns nothing
    call AddResourceAmount(whichUnit, delta)
endfunction
]]>
    </Function>

    <Function Name="GetConvertedPlayerId" ReturnType="integer" ArgumentList="player whichPlayer">
      <![CDATA[function GetConvertedPlayerId takes player whichPlayer returns integer
    return GetPlayerId(whichPlayer) + 1
endfunction
]]>
    </Function>

    <Function Name="ConvertedPlayer" ReturnType="player" ArgumentList="integer convertedPlayerId">
      <![CDATA[function ConvertedPlayer takes integer convertedPlayerId returns player
    return Player(convertedPlayerId - 1)
endfunction
]]>
    </Function>

    <Function Name="GetRectWidthBJ" ReturnType="real" ArgumentList="rect r">
      <![CDATA[function GetRectWidthBJ takes rect r returns real
    return GetRectMaxX(r) - GetRectMinX(r)
endfunction
]]>
    </Function>

    <Function Name="GetRectHeightBJ" ReturnType="real" ArgumentList="rect r">
      <![CDATA[function GetRectHeightBJ takes rect r returns real
    return GetRectMaxY(r) - GetRectMinY(r)
endfunction
]]>
    </Function>

    <Function Name="BlightGoldMineForPlayerBJ" ReturnType="unit" ArgumentList="unit goldMine, player whichPlayer">
      <![CDATA[function BlightGoldMineForPlayerBJ takes unit goldMine, player whichPlayer returns unit
    local real    mineX
    local real    mineY
    local integer mineGold
    local unit    newMine

    // Make sure we're replacing a Gold Mine and not some other type of unit.
    if GetUnitTypeId(goldMine) != 'ngol' then
        return null
    endif

    // Save the Gold Mine's properties and remove it.
    set mineX    = GetUnitX(goldMine)
    set mineY    = GetUnitY(goldMine)
    set mineGold = GetResourceAmount(goldMine)
    call RemoveUnit(goldMine)

    // Create a Haunted Gold Mine to replace the Gold Mine.
    set newMine = CreateBlightedGoldmine(whichPlayer, mineX, mineY, bj_UNIT_FACING)
    call SetResourceAmount(newMine, mineGold)
    return newMine
endfunction
]]>
    </Function>

    <Function Name="BlightGoldMineForPlayer" ReturnType="unit" ArgumentList="unit goldMine, player whichPlayer">
      <![CDATA[function BlightGoldMineForPlayer takes unit goldMine, player whichPlayer returns unit
    set bj_lastHauntedGoldMine = BlightGoldMineForPlayerBJ(goldMine, whichPlayer)
    return bj_lastHauntedGoldMine
endfunction
]]>
    </Function>

    <Function Name="GetLastHauntedGoldMine" ReturnType="unit" ArgumentList="nothing">
      <![CDATA[function GetLastHauntedGoldMine takes nothing returns unit
    return bj_lastHauntedGoldMine
endfunction
]]>
    </Function>

    <Function Name="SetPlayerColorBJEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetPlayerColorBJEnum takes nothing returns nothing
    call SetUnitColor(GetEnumUnit(), bj_setPlayerTargetColor)
endfunction
]]>
    </Function>

    <Function Name="SetPlayerColorBJ" ReturnType="nothing" ArgumentList="player whichPlayer, playercolor color, boolean changeExisting">
      <![CDATA[function SetPlayerColorBJ takes player whichPlayer, playercolor color, boolean changeExisting returns nothing
    local group g

    call SetPlayerColor(whichPlayer, color)
    if changeExisting then
        set bj_setPlayerTargetColor = color
        set g = CreateGroup()
        call GroupEnumUnitsOfPlayer(g, whichPlayer, null)
        call ForGroup(g, function SetPlayerColorBJEnum)
        call DestroyGroup(g)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetPlayerUnitAvailableBJ" ReturnType="nothing" ArgumentList="integer unitId, boolean allowed, player whichPlayer">
      <![CDATA[function SetPlayerUnitAvailableBJ takes integer unitId, boolean allowed, player whichPlayer returns nothing
    if allowed then
        call SetPlayerTechMaxAllowed(whichPlayer, unitId, -1)
    else
        call SetPlayerTechMaxAllowed(whichPlayer, unitId, 0)
    endif
endfunction
]]>
    </Function>

    <Function Name="LockGameSpeedBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function LockGameSpeedBJ takes nothing returns nothing
    call SetMapFlag(MAP_LOCK_SPEED, true)
endfunction
]]>
    </Function>

    <Function Name="UnlockGameSpeedBJ" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function UnlockGameSpeedBJ takes nothing returns nothing
    call SetMapFlag(MAP_LOCK_SPEED, false)
endfunction
]]>
    </Function>

    <Function Name="IssueTargetOrderBJ" ReturnType="boolean" ArgumentList="unit whichUnit, string order, widget targetWidget">
      <![CDATA[function IssueTargetOrderBJ takes unit whichUnit, string order, widget targetWidget returns boolean
    return IssueTargetOrder( whichUnit, order, targetWidget )
endfunction
]]>
    </Function>

    <Function Name="IssuePointOrderLocBJ" ReturnType="boolean" ArgumentList="unit whichUnit, string order, location whichLocation">
      <![CDATA[function IssuePointOrderLocBJ takes unit whichUnit, string order, location whichLocation returns boolean
    return IssuePointOrderLoc( whichUnit, order, whichLocation )
endfunction
]]>
    </Function>

    <Function Name="IssueTargetDestructableOrder" ReturnType="boolean" ArgumentList="unit whichUnit, string order, widget targetWidget">
      <![CDATA[function IssueTargetDestructableOrder takes unit whichUnit, string order, widget targetWidget returns boolean
    return IssueTargetOrder( whichUnit, order, targetWidget )
endfunction
]]>
    </Function>

    <Function Name="IssueImmediateOrderBJ" ReturnType="boolean" ArgumentList="unit whichUnit, string order">
      <![CDATA[function IssueImmediateOrderBJ takes unit whichUnit, string order returns boolean
    return IssueImmediateOrder( whichUnit, order )
endfunction
]]>
    </Function>

    <Function Name="GroupTargetOrderBJ" ReturnType="boolean" ArgumentList="group whichGroup, string order, widget targetWidget">
      <![CDATA[function GroupTargetOrderBJ takes group whichGroup, string order, widget targetWidget returns boolean
    return GroupTargetOrder( whichGroup, order, targetWidget )
endfunction
]]>
    </Function>

    <Function Name="GroupPointOrderLocBJ" ReturnType="boolean" ArgumentList="group whichGroup, string order, location whichLocation">
      <![CDATA[function GroupPointOrderLocBJ takes group whichGroup, string order, location whichLocation returns boolean
    return GroupPointOrderLoc( whichGroup, order, whichLocation )
endfunction
]]>
    </Function>

    <Function Name="GroupImmediateOrderBJ" ReturnType="boolean" ArgumentList="group whichGroup, string order">
      <![CDATA[function GroupImmediateOrderBJ takes group whichGroup, string order returns boolean
    return GroupImmediateOrder( whichGroup, order )
endfunction
]]>
    </Function>

    <Function Name="GroupTargetDestructableOrder" ReturnType="boolean" ArgumentList="group whichGroup, string order, widget targetWidget">
      <![CDATA[function GroupTargetDestructableOrder takes group whichGroup, string order, widget targetWidget returns boolean
    return GroupTargetOrder( whichGroup, order, targetWidget )
endfunction
]]>
    </Function>

    <Function Name="GetDyingDestructable" ReturnType="destructable" ArgumentList="nothing">
      <![CDATA[function GetDyingDestructable takes nothing returns destructable
    return GetTriggerWidget()
endfunction
]]>
    </Function>

    <Function Name="SaveDyingWidget" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SaveDyingWidget takes nothing returns nothing
    set bj_lastDyingWidget = GetTriggerWidget()
endfunction
]]>
    </Function>

    <Function Name="SetBlightRectBJ" ReturnType="nothing" ArgumentList="boolean addBlight, player whichPlayer, rect r">
      <![CDATA[function SetBlightRectBJ takes boolean addBlight, player whichPlayer, rect r returns nothing
    call SetBlightRect(whichPlayer, r, addBlight)
endfunction
]]>
    </Function>

    <Function Name="SetBlightRadiusLocBJ" ReturnType="nothing" ArgumentList="boolean addBlight, player whichPlayer, location loc, real radius">
      <![CDATA[function SetBlightRadiusLocBJ takes boolean addBlight, player whichPlayer, location loc, real radius returns nothing
    call SetBlightLoc(whichPlayer, loc, radius, addBlight)
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingVisibility" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeStartingVisibility takes nothing returns nothing
    // Start by setting the ToD.
    call SetFloatGameState(GAME_STATE_TIME_OF_DAY, bj_MELEE_STARTING_TOD)

    // call FogMaskEnable(true)
    // call FogEnable(true)
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingResources" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeStartingResources takes nothing returns nothing
    local integer index
    local player  indexPlayer
    local version v
    local integer startingGold
    local integer startingLumber

    set v = VersionGet()
    if (v == VERSION_REIGN_OF_CHAOS) then
        set startingGold = bj_MELEE_STARTING_GOLD_V0
        set startingLumber = bj_MELEE_STARTING_LUMBER_V0
    else
        set startingGold = bj_MELEE_STARTING_GOLD_V1
        set startingLumber = bj_MELEE_STARTING_LUMBER_V1
    endif

    // Set each player's starting resources.
    set index = 0
    loop
        set indexPlayer = Player(index)
        if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
            call SetPlayerState(indexPlayer, PLAYER_STATE_RESOURCE_GOLD, startingGold)
            call SetPlayerState(indexPlayer, PLAYER_STATE_RESOURCE_LUMBER, startingLumber)
        endif

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="ReducePlayerTechMaxAllowed" ReturnType="nothing" ArgumentList="player whichPlayer, integer techId, integer limit">
      <![CDATA[function ReducePlayerTechMaxAllowed takes player whichPlayer, integer techId, integer limit returns nothing
    local integer oldMax = GetPlayerTechMaxAllowed(whichPlayer, techId)

    // A value of -1 is used to indicate no limit, so check for that as well.
    if (oldMax < 0 or oldMax > limit) then
        call SetPlayerTechMaxAllowed(whichPlayer, techId, limit)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingHeroLimit" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeStartingHeroLimit takes nothing returns nothing
    local integer index

    set index = 0
    loop
        // max heroes per player
        call SetPlayerMaxHeroesAllowed(bj_MELEE_HERO_LIMIT, Player(index))

        // each player is restricted to a limit per hero type as well
        call ReducePlayerTechMaxAllowed(Player(index), 'Hamg', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Hmkg', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Hpal', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Hblm', bj_MELEE_HERO_TYPE_LIMIT)

        call ReducePlayerTechMaxAllowed(Player(index), 'Obla', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Ofar', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Otch', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Oshd', bj_MELEE_HERO_TYPE_LIMIT)

        call ReducePlayerTechMaxAllowed(Player(index), 'Edem', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Ekee', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Emoo', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Ewar', bj_MELEE_HERO_TYPE_LIMIT)

        call ReducePlayerTechMaxAllowed(Player(index), 'Udea', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Udre', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Ulic', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Ucrl', bj_MELEE_HERO_TYPE_LIMIT)

        call ReducePlayerTechMaxAllowed(Player(index), 'Npbm', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Nbrn', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Nngs', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Nplh', bj_MELEE_HERO_TYPE_LIMIT)
        call ReducePlayerTechMaxAllowed(Player(index), 'Nbst', bj_MELEE_HERO_TYPE_LIMIT)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="MeleeTrainedUnitIsHeroBJFilter" ReturnType="boolean" ArgumentList="nothing">
      <![CDATA[function MeleeTrainedUnitIsHeroBJFilter takes nothing returns boolean
    return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO)
endfunction
]]>
    </Function>

    <Function Name="MeleeGrantItemsToHero" ReturnType="nothing" ArgumentList="unit whichUnit">
      <![CDATA[function MeleeGrantItemsToHero takes unit whichUnit returns nothing
    local integer owner   = GetPlayerId(GetOwningPlayer(whichUnit))

    // If we haven't twinked N heroes for this player yet, twink away.
    if (bj_meleeTwinkedHeroes[owner] < bj_MELEE_MAX_TWINKED_HEROES) then
        call UnitAddItemById(whichUnit, 'stwp')
        set bj_meleeTwinkedHeroes[owner] = bj_meleeTwinkedHeroes[owner] + 1
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeGrantItemsToTrainedHero" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeGrantItemsToTrainedHero takes nothing returns nothing
    call MeleeGrantItemsToHero(GetTrainedUnit())
endfunction
]]>
    </Function>

    <Function Name="MeleeGrantItemsToHiredHero" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeGrantItemsToHiredHero takes nothing returns nothing
    call MeleeGrantItemsToHero(GetSoldUnit())
endfunction
]]>
    </Function>

    <Function Name="MeleeGrantHeroItems" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeGrantHeroItems takes nothing returns nothing
    local integer index
    local trigger trig

    // Initialize the twinked hero counts.
    set index = 0
    loop
        set bj_meleeTwinkedHeroes[index] = 0

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop

    // Register for an event whenever a hero is trained, so that we can give
    // him/her their starting items.
    set index = 0
    loop
        set trig = CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(trig, Player(index), EVENT_PLAYER_UNIT_TRAIN_FINISH, filterMeleeTrainedUnitIsHeroBJ)
        call TriggerAddAction(trig, function MeleeGrantItemsToTrainedHero)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop

    // Register for an event whenever a neutral hero is hired, so that we
    // can give him/her their starting items.
    set trig = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(trig, Player(PLAYER_NEUTRAL_PASSIVE), EVENT_PLAYER_UNIT_SELL, filterMeleeTrainedUnitIsHeroBJ)
    call TriggerAddAction(trig, function MeleeGrantItemsToHiredHero)

    // Flag that we are giving starting items to heroes, so that the melee
    // starting units code can create them as necessary.
    set bj_meleeGrantHeroItems = true
endfunction
]]>
    </Function>

    <Function Name="MeleeClearExcessUnit" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeClearExcessUnit takes nothing returns nothing
    local unit    theUnit = GetEnumUnit()
    local integer owner   = GetPlayerId(GetOwningPlayer(theUnit))

    if (owner == PLAYER_NEUTRAL_AGGRESSIVE) then
        // Remove any Neutral Hostile units from the area.
        call RemoveUnit(GetEnumUnit())
    elseif (owner == PLAYER_NEUTRAL_PASSIVE) then
        // Remove non-structure Neutral Passive units from the area.
        if not IsUnitType(theUnit, UNIT_TYPE_STRUCTURE) then
            call RemoveUnit(GetEnumUnit())
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeClearNearbyUnits" ReturnType="nothing" ArgumentList="real x, real y, real range">
      <![CDATA[function MeleeClearNearbyUnits takes real x, real y, real range returns nothing
    local group nearbyUnits
    
    set nearbyUnits = CreateGroup()
    call GroupEnumUnitsInRange(nearbyUnits, x, y, range, null)
    call ForGroup(nearbyUnits, function MeleeClearExcessUnit)
    call DestroyGroup(nearbyUnits)
endfunction
]]>
    </Function>

    <Function Name="MeleeClearExcessUnits" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeClearExcessUnits takes nothing returns nothing
    local integer index
    local real    locX
    local real    locY
    local player  indexPlayer

    set index = 0
    loop
        set indexPlayer = Player(index)

        // If the player slot is being used, clear any nearby creeps.
        if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
            set locX = GetStartLocationX(GetPlayerStartLocation(indexPlayer))
            set locY = GetStartLocationY(GetPlayerStartLocation(indexPlayer))

            call MeleeClearNearbyUnits(locX, locY, bj_MELEE_CLEAR_UNITS_RADIUS)
        endif

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="MeleeEnumFindNearestMine" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeEnumFindNearestMine takes nothing returns nothing
    local unit enumUnit = GetEnumUnit()
    local real dist
    local location unitLoc

    if (GetUnitTypeId(enumUnit) == 'ngol') then
        set unitLoc = GetUnitLoc(enumUnit)
        set dist = DistanceBetweenPoints(unitLoc, bj_meleeNearestMineToLoc)
        call RemoveLocation(unitLoc)

        // If this is our first mine, or the closest thusfar, use it instead.
        if (bj_meleeNearestMineDist < 0) or (dist < bj_meleeNearestMineDist) then
            set bj_meleeNearestMine = enumUnit
            set bj_meleeNearestMineDist = dist
        endif
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeFindNearestMine" ReturnType="unit" ArgumentList="location src, real range">
      <![CDATA[function MeleeFindNearestMine takes location src, real range returns unit
    local group nearbyMines

    set bj_meleeNearestMine = null
    set bj_meleeNearestMineDist = -1
    set bj_meleeNearestMineToLoc = src

    set nearbyMines = CreateGroup()
    call GroupEnumUnitsInRangeOfLoc(nearbyMines, src, range, null)
    call ForGroup(nearbyMines, function MeleeEnumFindNearestMine)
    call DestroyGroup(nearbyMines)

    return bj_meleeNearestMine
endfunction
]]>
    </Function>

    <Function Name="MeleeRandomHeroLoc" ReturnType="unit" ArgumentList="player p, integer id1, integer id2, integer id3, integer id4, location loc">
      <![CDATA[function MeleeRandomHeroLoc takes player p, integer id1, integer id2, integer id3, integer id4, location loc returns unit
    local unit    hero = null
	local integer roll
    local integer pick
    local version v

    // The selection of heroes is dependant on the game version.
    set v = VersionGet()
    if (v == VERSION_REIGN_OF_CHAOS) then
        set roll = GetRandomInt(1,3)
    else
        set roll = GetRandomInt(1,4)
    endif

    // Translate the roll into a unitid.
    if roll == 1 then
        set pick = id1
    elseif roll == 2 then
        set pick = id2
    elseif roll == 3 then
        set pick = id3
    elseif roll == 4 then
        set pick = id4
    else
        // Unrecognized id index - pick the first hero in the list.
        set pick = id1
    endif

    // Create the hero.
    set hero = CreateUnitAtLoc(p, pick, loc, bj_UNIT_FACING)
    if bj_meleeGrantHeroItems then
        call MeleeGrantItemsToHero(hero)
    endif
    return hero
endfunction
]]>
    </Function>

    <Function Name="MeleeGetProjectedLoc" ReturnType="location" ArgumentList="location src, location targ, real distance, real deltaAngle">
      <![CDATA[function MeleeGetProjectedLoc takes location src, location targ, real distance, real deltaAngle returns location
    local real srcX = GetLocationX(src)
    local real srcY = GetLocationY(src)
    local real direction = Atan2(GetLocationY(targ) - srcY, GetLocationX(targ) - srcX) + deltaAngle
    return Location(srcX + distance * Cos(direction), srcY + distance * Sin(direction))
endfunction
]]>
    </Function>

    <Function Name="MeleeGetNearestValueWithin" ReturnType="real" ArgumentList="real val, real minVal, real maxVal">
      <![CDATA[function MeleeGetNearestValueWithin takes real val, real minVal, real maxVal returns real
    if (val < minVal) then
        return minVal
    elseif (val > maxVal) then
        return maxVal
    else
        return val
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeGetLocWithinRect" ReturnType="location" ArgumentList="location src, rect r">
      <![CDATA[function MeleeGetLocWithinRect takes location src, rect r returns location
    local real withinX = MeleeGetNearestValueWithin(GetLocationX(src), GetRectMinX(r), GetRectMaxX(r))
    local real withinY = MeleeGetNearestValueWithin(GetLocationY(src), GetRectMinY(r), GetRectMaxY(r))
    return Location(withinX, withinY)
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingUnitsHuman" ReturnType="nothing" ArgumentList="player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload">
      <![CDATA[function MeleeStartingUnitsHuman takes player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload returns nothing
    local boolean  useRandomHero = IsMapFlagSet(MAP_RANDOM_HERO)
    local real     unitSpacing   = 64.00
    local unit     nearestMine
    local location nearMineLoc
    local location heroLoc
    local real     peonX
    local real     peonY

    if (doPreload) then
        call Preloader( "scripts\\HumanMelee.pld" )
    endif

    set nearestMine = MeleeFindNearestMine(startLoc, bj_MELEE_MINE_SEARCH_RADIUS)
    if (nearestMine != null) then
        // Spawn Town Hall at the start location.
        call CreateUnitAtLoc(whichPlayer, 'htow', startLoc, bj_UNIT_FACING)
        
        // Spawn Peasants near the mine.
        set nearMineLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 320, 0)
        set peonX = GetLocationX(nearMineLoc)
        set peonY = GetLocationY(nearMineLoc)
        call CreateUnit(whichPlayer, 'hpea', peonX + 0.00 * unitSpacing, peonY + 1.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'hpea', peonX + 1.00 * unitSpacing, peonY + 0.15 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'hpea', peonX - 1.00 * unitSpacing, peonY + 0.15 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'hpea', peonX + 0.60 * unitSpacing, peonY - 1.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'hpea', peonX - 0.60 * unitSpacing, peonY - 1.00 * unitSpacing, bj_UNIT_FACING)

        // Set random hero spawn point to be off to the side of the start location.
        set heroLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 384, 45)
    else
        // Spawn Town Hall at the start location.
        call CreateUnitAtLoc(whichPlayer, 'htow', startLoc, bj_UNIT_FACING)
        
        // Spawn Peasants directly south of the town hall.
        set peonX = GetLocationX(startLoc)
        set peonY = GetLocationY(startLoc) - 224.00
        call CreateUnit(whichPlayer, 'hpea', peonX + 2.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'hpea', peonX + 1.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'hpea', peonX + 0.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'hpea', peonX - 1.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'hpea', peonX - 2.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)

        // Set random hero spawn point to be just south of the start location.
        set heroLoc = Location(peonX, peonY - 2.00 * unitSpacing)
    endif

    if (doHeroes) then
        // If the "Random Hero" option is set, start the player with a random hero.
        // Otherwise, give them a "free hero" token.
        if useRandomHero then
            call MeleeRandomHeroLoc(whichPlayer, 'Hamg', 'Hmkg', 'Hpal', 'Hblm', heroLoc)
        else
            call SetPlayerState(whichPlayer, PLAYER_STATE_RESOURCE_HERO_TOKENS, bj_MELEE_STARTING_HERO_TOKENS)
        endif
    endif

    if (doCamera) then
        // Center the camera on the initial Peasants.
        call SetCameraPositionForPlayer(whichPlayer, peonX, peonY)
        call SetCameraQuickPositionForPlayer(whichPlayer, peonX, peonY)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingUnitsOrc" ReturnType="nothing" ArgumentList="player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload">
      <![CDATA[function MeleeStartingUnitsOrc takes player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload returns nothing
    local boolean  useRandomHero = IsMapFlagSet(MAP_RANDOM_HERO)
    local real     unitSpacing   = 64.00
    local unit     nearestMine
    local location nearMineLoc
    local location heroLoc
    local real     peonX
    local real     peonY

    if (doPreload) then
        call Preloader( "scripts\\OrcMelee.pld" )
    endif

    set nearestMine = MeleeFindNearestMine(startLoc, bj_MELEE_MINE_SEARCH_RADIUS)
    if (nearestMine != null) then
        // Spawn Great Hall at the start location.
        call CreateUnitAtLoc(whichPlayer, 'ogre', startLoc, bj_UNIT_FACING)
        
        // Spawn Peons near the mine.
        set nearMineLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 320, 0)
        set peonX = GetLocationX(nearMineLoc)
        set peonY = GetLocationY(nearMineLoc)
        call CreateUnit(whichPlayer, 'opeo', peonX + 0.00 * unitSpacing, peonY + 1.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'opeo', peonX + 1.00 * unitSpacing, peonY + 0.15 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'opeo', peonX - 1.00 * unitSpacing, peonY + 0.15 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'opeo', peonX + 0.60 * unitSpacing, peonY - 1.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'opeo', peonX - 0.60 * unitSpacing, peonY - 1.00 * unitSpacing, bj_UNIT_FACING)

        // Set random hero spawn point to be off to the side of the start location.
        set heroLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 384, 45)
    else
        // Spawn Great Hall at the start location.
        call CreateUnitAtLoc(whichPlayer, 'ogre', startLoc, bj_UNIT_FACING)
        
        // Spawn Peons directly south of the town hall.
        set peonX = GetLocationX(startLoc)
        set peonY = GetLocationY(startLoc) - 224.00
        call CreateUnit(whichPlayer, 'opeo', peonX + 2.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'opeo', peonX + 1.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'opeo', peonX + 0.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'opeo', peonX - 1.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'opeo', peonX - 2.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)

        // Set random hero spawn point to be just south of the start location.
        set heroLoc = Location(peonX, peonY - 2.00 * unitSpacing)
    endif

    if (doHeroes) then
        // If the "Random Hero" option is set, start the player with a random hero.
        // Otherwise, give them a "free hero" token.
        if useRandomHero then
            call MeleeRandomHeroLoc(whichPlayer, 'Obla', 'Ofar', 'Otch', 'Oshd', heroLoc)
        else
            call SetPlayerState(whichPlayer, PLAYER_STATE_RESOURCE_HERO_TOKENS, bj_MELEE_STARTING_HERO_TOKENS)
        endif
    endif

    if (doCamera) then
        // Center the camera on the initial Peons.
        call SetCameraPositionForPlayer(whichPlayer, peonX, peonY)
        call SetCameraQuickPositionForPlayer(whichPlayer, peonX, peonY)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingUnitsUndead" ReturnType="nothing" ArgumentList="player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload">
      <![CDATA[function MeleeStartingUnitsUndead takes player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload returns nothing
    local boolean  useRandomHero = IsMapFlagSet(MAP_RANDOM_HERO)
    local real     unitSpacing   = 64.00
    local unit     nearestMine
    local location nearMineLoc
    local location nearTownLoc
    local location heroLoc
    local real     peonX
    local real     peonY
    local real     ghoulX
    local real     ghoulY

    if (doPreload) then
        call Preloader( "scripts\\UndeadMelee.pld" )
    endif

    set nearestMine = MeleeFindNearestMine(startLoc, bj_MELEE_MINE_SEARCH_RADIUS)
    if (nearestMine != null) then
        // Spawn Necropolis at the start location.
        call CreateUnitAtLoc(whichPlayer, 'unpl', startLoc, bj_UNIT_FACING)
        
        // Replace the nearest gold mine with a blighted version.
        set nearestMine = BlightGoldMineForPlayerBJ(nearestMine, whichPlayer)

        // Spawn Ghoul near the Necropolis.
        set nearTownLoc = MeleeGetProjectedLoc(startLoc, GetUnitLoc(nearestMine), 288, 0)
        set ghoulX = GetLocationX(nearTownLoc)
        set ghoulY = GetLocationY(nearTownLoc)
        set bj_ghoul[GetPlayerId(whichPlayer)] = CreateUnit(whichPlayer, 'ugho', ghoulX + 0.00 * unitSpacing, ghoulY + 0.00 * unitSpacing, bj_UNIT_FACING)

        // Spawn Acolytes near the mine.
        set nearMineLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 320, 0)
        set peonX = GetLocationX(nearMineLoc)
        set peonY = GetLocationY(nearMineLoc)
        call CreateUnit(whichPlayer, 'uaco', peonX + 0.00 * unitSpacing, peonY + 0.50 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'uaco', peonX + 0.65 * unitSpacing, peonY - 0.50 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'uaco', peonX - 0.65 * unitSpacing, peonY - 0.50 * unitSpacing, bj_UNIT_FACING)

        // Create a patch of blight around the gold mine.
        call SetBlightLoc(whichPlayer,nearMineLoc, 768, true)

        // Set random hero spawn point to be off to the side of the start location.
        set heroLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 384, 45)
    else
        // Spawn Necropolis at the start location.
        call CreateUnitAtLoc(whichPlayer, 'unpl', startLoc, bj_UNIT_FACING)
        
        // Spawn Acolytes and Ghoul directly south of the Necropolis.
        set peonX = GetLocationX(startLoc)
        set peonY = GetLocationY(startLoc) - 224.00
        call CreateUnit(whichPlayer, 'uaco', peonX - 1.50 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'uaco', peonX - 0.50 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'uaco', peonX + 0.50 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ugho', peonX + 1.50 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)

        // Create a patch of blight around the start location.
        call SetBlightLoc(whichPlayer,startLoc, 768, true)

        // Set random hero spawn point to be just south of the start location.
        set heroLoc = Location(peonX, peonY - 2.00 * unitSpacing)
    endif

    if (doHeroes) then
        // If the "Random Hero" option is set, start the player with a random hero.
        // Otherwise, give them a "free hero" token.
        if useRandomHero then
            call MeleeRandomHeroLoc(whichPlayer, 'Udea', 'Udre', 'Ulic', 'Ucrl', heroLoc)
        else
            call SetPlayerState(whichPlayer, PLAYER_STATE_RESOURCE_HERO_TOKENS, bj_MELEE_STARTING_HERO_TOKENS)
        endif
    endif

    if (doCamera) then
        // Center the camera on the initial Acolytes.
        call SetCameraPositionForPlayer(whichPlayer, peonX, peonY)
        call SetCameraQuickPositionForPlayer(whichPlayer, peonX, peonY)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingUnitsNightElf" ReturnType="nothing" ArgumentList="player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload">
      <![CDATA[function MeleeStartingUnitsNightElf takes player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload returns nothing
    local boolean  useRandomHero = IsMapFlagSet(MAP_RANDOM_HERO)
    local real     unitSpacing   = 64.00
    local real     minTreeDist   = 3.50 * bj_CELLWIDTH
    local real     minWispDist   = 1.75 * bj_CELLWIDTH
    local unit     nearestMine
    local location nearMineLoc
    local location wispLoc
    local location heroLoc
    local real     peonX
    local real     peonY
    local unit     tree

    if (doPreload) then
        call Preloader( "scripts\\NightElfMelee.pld" )
    endif

    set nearestMine = MeleeFindNearestMine(startLoc, bj_MELEE_MINE_SEARCH_RADIUS)
    if (nearestMine != null) then
        // Spawn Tree of Life near the mine and have it entangle the mine.
        // Project the Tree's coordinates from the gold mine, and then snap
        // the X and Y values to within minTreeDist of the Gold Mine.
        set nearMineLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 650, 0)
        set nearMineLoc = MeleeGetLocWithinRect(nearMineLoc, GetRectFromCircleBJ(GetUnitLoc(nearestMine), minTreeDist))
        set tree = CreateUnitAtLoc(whichPlayer, 'etol', nearMineLoc, bj_UNIT_FACING)
        call IssueTargetOrder(tree, "entangleinstant", nearestMine)

        // Spawn Wisps at the start location.
        set wispLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 320, 0)
        set wispLoc = MeleeGetLocWithinRect(wispLoc, GetRectFromCircleBJ(GetUnitLoc(nearestMine), minWispDist))
        set peonX = GetLocationX(wispLoc)
        set peonY = GetLocationY(wispLoc)
        call CreateUnit(whichPlayer, 'ewsp', peonX + 0.00 * unitSpacing, peonY + 1.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ewsp', peonX + 1.00 * unitSpacing, peonY + 0.15 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ewsp', peonX - 1.00 * unitSpacing, peonY + 0.15 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ewsp', peonX + 0.58 * unitSpacing, peonY - 1.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ewsp', peonX - 0.58 * unitSpacing, peonY - 1.00 * unitSpacing, bj_UNIT_FACING)

        // Set random hero spawn point to be off to the side of the start location.
        set heroLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 384, 45)
    else
        // Spawn Tree of Life at the start location.
        call CreateUnitAtLoc(whichPlayer, 'etol', startLoc, bj_UNIT_FACING)

        // Spawn Wisps directly south of the town hall.
        set peonX = GetLocationX(startLoc)
        set peonY = GetLocationY(startLoc) - 224.00
        call CreateUnit(whichPlayer, 'ewsp', peonX - 2.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ewsp', peonX - 1.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ewsp', peonX + 0.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ewsp', peonX + 1.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)
        call CreateUnit(whichPlayer, 'ewsp', peonX + 2.00 * unitSpacing, peonY + 0.00 * unitSpacing, bj_UNIT_FACING)

        // Set random hero spawn point to be just south of the start location.
        set heroLoc = Location(peonX, peonY - 2.00 * unitSpacing)
    endif

    if (doHeroes) then
        // If the "Random Hero" option is set, start the player with a random hero.
        // Otherwise, give them a "free hero" token.
        if useRandomHero then
            call MeleeRandomHeroLoc(whichPlayer, 'Edem', 'Ekee', 'Emoo', 'Ewar', heroLoc)
        else
            call SetPlayerState(whichPlayer, PLAYER_STATE_RESOURCE_HERO_TOKENS, bj_MELEE_STARTING_HERO_TOKENS)
        endif
    endif

    if (doCamera) then
        // Center the camera on the initial Wisps.
        call SetCameraPositionForPlayer(whichPlayer, peonX, peonY)
        call SetCameraQuickPositionForPlayer(whichPlayer, peonX, peonY)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingUnitsUnknownRace" ReturnType="nothing" ArgumentList="player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload">
      <![CDATA[function MeleeStartingUnitsUnknownRace takes player whichPlayer, location startLoc, boolean doHeroes, boolean doCamera, boolean doPreload returns nothing
    local integer index

    if (doPreload) then
    endif

    set index = 0
    loop
        call CreateUnit(whichPlayer, 'nshe', GetLocationX(startLoc) + GetRandomReal(-256, 256), GetLocationY(startLoc) + GetRandomReal(-256, 256), GetRandomReal(0, 360))
        set index = index + 1
        exitwhen index == 12
    endloop

    if (doHeroes) then
        // Give them a "free hero" token, out of pity.
        call SetPlayerState(whichPlayer, PLAYER_STATE_RESOURCE_HERO_TOKENS, bj_MELEE_STARTING_HERO_TOKENS)
    endif

    if (doCamera) then
        // Center the camera on the initial sheep.
        call SetCameraPositionLocForPlayer(whichPlayer, startLoc)
        call SetCameraQuickPositionLocForPlayer(whichPlayer, startLoc)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingUnits" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeStartingUnits takes nothing returns nothing
    local integer  index
    local player   indexPlayer
    local location indexStartLoc
    local race     indexRace

    call Preloader( "scripts\\SharedMelee.pld" )

    set index = 0
    loop
        set indexPlayer = Player(index)
        if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
            set indexStartLoc = GetStartLocationLoc(GetPlayerStartLocation(indexPlayer))
            set indexRace = GetPlayerRace(indexPlayer)

            // Create initial race-specific starting units
            if (indexRace == RACE_HUMAN) then
                call MeleeStartingUnitsHuman(indexPlayer, indexStartLoc, true, true, true)
            elseif (indexRace == RACE_ORC) then
                call MeleeStartingUnitsOrc(indexPlayer, indexStartLoc, true, true, true)
            elseif (indexRace == RACE_UNDEAD) then
                call MeleeStartingUnitsUndead(indexPlayer, indexStartLoc, true, true, true)
            elseif (indexRace == RACE_NIGHTELF) then
                call MeleeStartingUnitsNightElf(indexPlayer, indexStartLoc, true, true, true)
            else
                call MeleeStartingUnitsUnknownRace(indexPlayer, indexStartLoc, true, true, true)
            endif
        endif

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
    
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingUnitsForPlayer" ReturnType="nothing" ArgumentList="race whichRace, player whichPlayer, location loc, boolean doHeroes">
      <![CDATA[function MeleeStartingUnitsForPlayer takes race whichRace, player whichPlayer, location loc, boolean doHeroes returns nothing
    // Create initial race-specific starting units
    if (whichRace == RACE_HUMAN) then
        call MeleeStartingUnitsHuman(whichPlayer, loc, doHeroes, false, false)
    elseif (whichRace == RACE_ORC) then
        call MeleeStartingUnitsOrc(whichPlayer, loc, doHeroes, false, false)
    elseif (whichRace == RACE_UNDEAD) then
        call MeleeStartingUnitsUndead(whichPlayer, loc, doHeroes, false, false)
    elseif (whichRace == RACE_NIGHTELF) then
        call MeleeStartingUnitsNightElf(whichPlayer, loc, doHeroes, false, false)
    else
        // Unrecognized race - ignore the request.
    endif
endfunction
]]>
    </Function>

    <Function Name="PickMeleeAI" ReturnType="nothing" ArgumentList="player num, string s1, string s2, string s3">
      <![CDATA[function PickMeleeAI takes player num, string s1, string s2, string s3 returns nothing
    local integer pick

    // easy difficulty never uses any custom AI scripts
    // that are designed to be a bit more challenging
    //
    if GetAIDifficulty(num) == AI_DIFFICULTY_NEWBIE then
        call StartMeleeAI(num,s1)
        return
    endif

    if s2 == null then
        set pick = 1
    elseif s3 == null then
        set pick = GetRandomInt(1,2)
    else
        set pick = GetRandomInt(1,3)
    endif

    if pick == 1 then
        call StartMeleeAI(num,s1)
    elseif pick == 2 then
        call StartMeleeAI(num,s2)
    else
        call StartMeleeAI(num,s3)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeStartingAI" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeStartingAI takes nothing returns nothing
    local integer index
    local player  indexPlayer
    local race    indexRace

    set index = 0
    loop
        set indexPlayer = Player(index)
        if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
            set indexRace = GetPlayerRace(indexPlayer)
            if (GetPlayerController(indexPlayer) == MAP_CONTROL_COMPUTER) then
                // Run a race-specific melee AI script.
                if (indexRace == RACE_HUMAN) then
                    call PickMeleeAI(indexPlayer, "human.ai", null, null)
                elseif (indexRace == RACE_ORC) then
                    call PickMeleeAI(indexPlayer, "orc.ai", null, null)
                elseif (indexRace == RACE_UNDEAD) then
                    call PickMeleeAI(indexPlayer, "undead.ai", null, null)
                    call RecycleGuardPosition(bj_ghoul[index])
                elseif (indexRace == RACE_NIGHTELF) then
                    call PickMeleeAI(indexPlayer, "elf.ai", null, null)
                else
                    // Unrecognized race.
                endif
                call ShareEverythingWithTeamAI(indexPlayer)
            endif
        endif

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="LockGuardPosition" ReturnType="nothing" ArgumentList="unit targ">
      <![CDATA[function LockGuardPosition takes unit targ returns nothing
    call SetUnitCreepGuard(targ,true)
endfunction
]]>
    </Function>

    <Function Name="MeleePlayerIsOpponent" ReturnType="boolean" ArgumentList="integer playerIndex, integer opponentIndex">
      <![CDATA[function MeleePlayerIsOpponent takes integer playerIndex, integer opponentIndex returns boolean
    local player thePlayer = Player(playerIndex)
    local player theOpponent = Player(opponentIndex)

    // The player himself is not an opponent.
    if (playerIndex == opponentIndex) then
        return false
    endif

    // Unused player slots are not opponents.
    if (GetPlayerSlotState(theOpponent) != PLAYER_SLOT_STATE_PLAYING) then
        return false
    endif

    // Players who are already defeated are not opponents.
    if (bj_meleeDefeated[opponentIndex]) then
        return false
    endif

    // Allied players with allied victory set are not opponents.
    if GetPlayerAlliance(thePlayer, theOpponent, ALLIANCE_PASSIVE) then
        if GetPlayerAlliance(theOpponent, thePlayer, ALLIANCE_PASSIVE) then
            if (GetPlayerState(thePlayer, PLAYER_STATE_ALLIED_VICTORY) == 1) then
                if (GetPlayerState(theOpponent, PLAYER_STATE_ALLIED_VICTORY) == 1) then
                    return false
                endif
            endif
        endif
    endif

    return true
endfunction
]]>
    </Function>

    <Function Name="MeleeGetAllyStructureCount" ReturnType="integer" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeGetAllyStructureCount takes player whichPlayer returns integer
    local integer    playerIndex
    local integer    buildingCount
    local player     indexPlayer

    // Count the number of buildings controlled by all not-yet-defeated co-allies.
    set buildingCount = 0
    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)

        // uncomment to cause defeat even if you have control of ally structures, but yours have been nixed
        //if (PlayersAreCoAllied(whichPlayer, indexPlayer) and not bj_meleeDefeated[playerIndex]) then
        if (PlayersAreCoAllied(whichPlayer, indexPlayer)) then
            set buildingCount = buildingCount + GetPlayerStructureCount(indexPlayer, true)
        endif
            
        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop

    return buildingCount
endfunction
]]>
    </Function>

    <Function Name="MeleeGetAllyCount" ReturnType="integer" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeGetAllyCount takes player whichPlayer returns integer
    local integer playerIndex
    local integer playerCount
    local player  indexPlayer

    // Count the number of not-yet-defeated co-allies.
    set playerCount = 0
    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if PlayersAreCoAllied(whichPlayer, indexPlayer) and not bj_meleeDefeated[playerIndex] and (whichPlayer != indexPlayer) then
            set playerCount = playerCount + 1
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop

    return playerCount
endfunction
]]>
    </Function>

    <Function Name="MeleeGetAllyKeyStructureCount" ReturnType="integer" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeGetAllyKeyStructureCount takes player whichPlayer returns integer
    local integer    playerIndex
    local player     indexPlayer
    local integer    keyStructs

    // Count the number of buildings controlled by all not-yet-defeated co-allies.
    set keyStructs = 0
    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if (PlayersAreCoAllied(whichPlayer, indexPlayer)) then
            set keyStructs = keyStructs + GetPlayerTypedUnitCount(indexPlayer, "townhall", true, true)
            set keyStructs = keyStructs + GetPlayerTypedUnitCount(indexPlayer, "greathall", true, true)
            set keyStructs = keyStructs + GetPlayerTypedUnitCount(indexPlayer, "treeoflife", true, true)
            set keyStructs = keyStructs + GetPlayerTypedUnitCount(indexPlayer, "necropolis", true, true)
        endif
            
        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop

    return keyStructs
endfunction
]]>
    </Function>

    <Function Name="MeleeDoDrawEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeDoDrawEnum takes nothing returns nothing
    local player thePlayer = GetEnumPlayer()

	call CachePlayerHeroData(thePlayer)
    call RemovePlayerPreserveUnitsBJ(thePlayer, PLAYER_GAME_RESULT_TIE, false)
endfunction
]]>
    </Function>

    <Function Name="MeleeDoVictoryEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeDoVictoryEnum takes nothing returns nothing
    local player thePlayer = GetEnumPlayer()
    local integer playerIndex = GetPlayerId(thePlayer)

    if (not bj_meleeVictoried[playerIndex]) then
        set bj_meleeVictoried[playerIndex] = true
		call CachePlayerHeroData(thePlayer)
        call RemovePlayerPreserveUnitsBJ(thePlayer, PLAYER_GAME_RESULT_VICTORY, false)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeDoDefeat" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeDoDefeat takes player whichPlayer returns nothing
    set bj_meleeDefeated[GetPlayerId(whichPlayer)] = true
    call RemovePlayerPreserveUnitsBJ(whichPlayer, PLAYER_GAME_RESULT_DEFEAT, false)
endfunction
]]>
    </Function>

    <Function Name="MeleeDoDefeatEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeDoDefeatEnum takes nothing returns nothing
    local player thePlayer = GetEnumPlayer()

	// needs to happen before ownership change
	call CachePlayerHeroData(thePlayer)
    call MakeUnitsPassiveForTeam(thePlayer)
    call MeleeDoDefeat(thePlayer)
endfunction
]]>
    </Function>

    <Function Name="MeleeDoLeave" ReturnType="nothing" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeDoLeave takes player whichPlayer returns nothing
    if (GetIntegerGameState(GAME_STATE_DISCONNECTED) != 0) then
        call GameOverDialogBJ( whichPlayer, true )
    else
        set bj_meleeDefeated[GetPlayerId(whichPlayer)] = true
        call RemovePlayerPreserveUnitsBJ(whichPlayer, PLAYER_GAME_RESULT_DEFEAT, true)
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeRemoveObservers" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeRemoveObservers takes nothing returns nothing
    local integer    playerIndex
    local player     indexPlayer

    // Give all observers the game over dialog
    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)

        if (IsPlayerObserver(indexPlayer)) then
            call RemovePlayerPreserveUnitsBJ(indexPlayer, PLAYER_GAME_RESULT_NEUTRAL, false)
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="MeleeCheckForVictors" ReturnType="force" ArgumentList="nothing">
      <![CDATA[function MeleeCheckForVictors takes nothing returns force
    local integer    playerIndex
    local integer    opponentIndex
    local force      opponentlessPlayers = CreateForce()
    local boolean    gameOver = false

    // Check to see if any players have opponents remaining.
    set playerIndex = 0
    loop
        if (not bj_meleeDefeated[playerIndex]) then
            // Determine whether or not this player has any remaining opponents.
            set opponentIndex = 0
            loop
                // If anyone has an opponent, noone can be victorious yet.
                if MeleePlayerIsOpponent(playerIndex, opponentIndex) then
                    return CreateForce()
                endif

                set opponentIndex = opponentIndex + 1
                exitwhen opponentIndex == bj_MAX_PLAYERS
            endloop

            // Keep track of each opponentless player so that we can give
            // them a victory later.
            call ForceAddPlayer(opponentlessPlayers, Player(playerIndex))
            set gameOver = true
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop

    // Set the game over global flag
    set bj_meleeGameOver = gameOver

    return opponentlessPlayers
endfunction
]]>
    </Function>

    <Function Name="MeleeCheckForLosersAndVictors" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeCheckForLosersAndVictors takes nothing returns nothing
    local integer    playerIndex
    local player     indexPlayer
    local force      defeatedPlayers = CreateForce()
    local force      victoriousPlayers
    local boolean    gameOver = false

    // If the game is already over, do nothing
    if (bj_meleeGameOver) then
        return
    endif

    // If the game was disconnected then it is over, in this case we
    // don't want to report results for anyone as they will most likely
    // conflict with the actual game results
    if (GetIntegerGameState(GAME_STATE_DISCONNECTED) != 0) then
        set bj_meleeGameOver = true
        return
    endif

    // Check each player to see if he or she has been defeated yet.
    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)

        if (not bj_meleeDefeated[playerIndex] and not bj_meleeVictoried[playerIndex]) then
            //call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "Player"+I2S(playerIndex)+" has "+I2S(MeleeGetAllyStructureCount(indexPlayer))+" ally buildings.")
            if (MeleeGetAllyStructureCount(indexPlayer) <= 0) then

                // Keep track of each defeated player so that we can give
                // them a defeat later.
                call ForceAddPlayer(defeatedPlayers, Player(playerIndex))

                // Set their defeated flag now so MeleeCheckForVictors
                // can detect victors.
                set bj_meleeDefeated[playerIndex] = true
            endif
        endif
            
        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop

    // Now that the defeated flags are set, check if there are any victors
    set victoriousPlayers = MeleeCheckForVictors()

    // Defeat all defeated players
    call ForForce(defeatedPlayers, function MeleeDoDefeatEnum)

    // Give victory to all victorious players
    call ForForce(victoriousPlayers, function MeleeDoVictoryEnum)

    // If the game is over we should remove all observers
    if (bj_meleeGameOver) then
        call MeleeRemoveObservers()
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeGetCrippledWarningMessage" ReturnType="string" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeGetCrippledWarningMessage takes player whichPlayer returns string
    local race r = GetPlayerRace(whichPlayer)

    if (r == RACE_HUMAN) then
        return GetLocalizedString("CRIPPLE_WARNING_HUMAN")
    elseif (r == RACE_ORC) then
        return GetLocalizedString("CRIPPLE_WARNING_ORC")
    elseif (r == RACE_NIGHTELF) then
        return GetLocalizedString("CRIPPLE_WARNING_NIGHTELF")
    elseif (r == RACE_UNDEAD) then
        return GetLocalizedString("CRIPPLE_WARNING_UNDEAD")
    else
        // Unrecognized Race
        return ""
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeGetCrippledTimerMessage" ReturnType="string" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeGetCrippledTimerMessage takes player whichPlayer returns string
    local race r = GetPlayerRace(whichPlayer)

    if (r == RACE_HUMAN) then
        return GetLocalizedString("CRIPPLE_TIMER_HUMAN")
    elseif (r == RACE_ORC) then
        return GetLocalizedString("CRIPPLE_TIMER_ORC")
    elseif (r == RACE_NIGHTELF) then
        return GetLocalizedString("CRIPPLE_TIMER_NIGHTELF")
    elseif (r == RACE_UNDEAD) then
        return GetLocalizedString("CRIPPLE_TIMER_UNDEAD")
    else
        // Unrecognized Race
        return ""
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeGetCrippledRevealedMessage" ReturnType="string" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeGetCrippledRevealedMessage takes player whichPlayer returns string
    return GetLocalizedString("CRIPPLE_REVEALING_PREFIX") + GetPlayerName(whichPlayer) + GetLocalizedString("CRIPPLE_REVEALING_POSTFIX")
endfunction
]]>
    </Function>

    <Function Name="MeleeExposePlayer" ReturnType="nothing" ArgumentList="player whichPlayer, boolean expose">
      <![CDATA[function MeleeExposePlayer takes player whichPlayer, boolean expose returns nothing
    local integer playerIndex
    local player  indexPlayer
    local force   toExposeTo = CreateForce()

    call CripplePlayer( whichPlayer, toExposeTo, false )

    set bj_playerIsExposed[GetPlayerId(whichPlayer)] = expose
    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if (not PlayersAreCoAllied(whichPlayer, indexPlayer)) then
            call ForceAddPlayer( toExposeTo, indexPlayer )
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop

    call CripplePlayer( whichPlayer, toExposeTo, expose )
    call DestroyForce(toExposeTo)
endfunction
]]>
    </Function>

    <Function Name="MeleeExposeAllPlayers" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeExposeAllPlayers takes nothing returns nothing
    local integer playerIndex
    local player  indexPlayer
    local integer playerIndex2
    local player  indexPlayer2
    local force   toExposeTo = CreateForce()

    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)

        call ForceClear( toExposeTo )
        call CripplePlayer( indexPlayer, toExposeTo, false )

        set playerIndex2 = 0
        loop
            set indexPlayer2 = Player(playerIndex2)

            if playerIndex != playerIndex2 then
                if (not PlayersAreCoAllied(indexPlayer, indexPlayer2)) then
                    call ForceAddPlayer( toExposeTo, indexPlayer2 )
                endif
            endif

            set playerIndex2 = playerIndex2 + 1
            exitwhen playerIndex2 == bj_MAX_PLAYERS
        endloop

        call CripplePlayer( indexPlayer, toExposeTo, true )

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop

    call DestroyForce( toExposeTo )
endfunction
]]>
    </Function>

    <Function Name="MeleeCrippledPlayerTimeout" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeCrippledPlayerTimeout takes nothing returns nothing
    local timer expiredTimer = GetExpiredTimer()
    local integer playerIndex
    local player  exposedPlayer

    // Determine which player's timer expired.
    set playerIndex = 0
    loop
        if (bj_crippledTimer[playerIndex] == expiredTimer) then
            exitwhen true
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop
    if (playerIndex == bj_MAX_PLAYERS) then
        return
    endif
    set exposedPlayer = Player(playerIndex)

    if (GetLocalPlayer() == exposedPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        // Hide the timer window for this player.
        call TimerDialogDisplay(bj_crippledTimerWindows[playerIndex], false)
    endif

    // Display a text message to all players, explaining the exposure.
    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, bj_MELEE_CRIPPLE_MSG_DURATION, MeleeGetCrippledRevealedMessage(exposedPlayer))

    // Expose the player.
    call MeleeExposePlayer(exposedPlayer, true)
endfunction
]]>
    </Function>

    <Function Name="MeleePlayerIsCrippled" ReturnType="boolean" ArgumentList="player whichPlayer">
      <![CDATA[function MeleePlayerIsCrippled takes player whichPlayer returns boolean
    local integer allyStructures    = MeleeGetAllyStructureCount(whichPlayer)
    local integer allyKeyStructures = MeleeGetAllyKeyStructureCount(whichPlayer)

    // Dead teams are not considered to be crippled.
    return (allyStructures > 0) and (allyKeyStructures <= 0)
endfunction
]]>
    </Function>

    <Function Name="MeleeCheckForCrippledPlayers" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeCheckForCrippledPlayers takes nothing returns nothing
    local integer    playerIndex
    local player     indexPlayer
    local force      crippledPlayers = CreateForce()
    local boolean    isNowCrippled
    local race       indexRace

    // The "finish soon" exposure of all players overrides any "crippled" exposure
    if bj_finishSoonAllExposed then
        return
    endif

    // Check each player to see if he or she has been crippled or uncrippled.
    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        set isNowCrippled = MeleePlayerIsCrippled(indexPlayer)

        if (not bj_playerIsCrippled[playerIndex] and isNowCrippled) then

            // Player became crippled; start their cripple timer.
            set bj_playerIsCrippled[playerIndex] = true
            call TimerStart(bj_crippledTimer[playerIndex], bj_MELEE_CRIPPLE_TIMEOUT, false, function MeleeCrippledPlayerTimeout)

            if (GetLocalPlayer() == indexPlayer) then
                // Use only local code (no net traffic) within this block to avoid desyncs.

                // Show the timer window.
                call TimerDialogDisplay(bj_crippledTimerWindows[playerIndex], true)

                // Display a warning message.
                call DisplayTimedTextToPlayer(indexPlayer, 0, 0, bj_MELEE_CRIPPLE_MSG_DURATION, MeleeGetCrippledWarningMessage(indexPlayer))
            endif

        elseif (bj_playerIsCrippled[playerIndex] and not isNowCrippled) then

            // Player became uncrippled; stop their cripple timer.
            set bj_playerIsCrippled[playerIndex] = false
            call PauseTimer(bj_crippledTimer[playerIndex])

            if (GetLocalPlayer() == indexPlayer) then
                // Use only local code (no net traffic) within this block to avoid desyncs.

                // Hide the timer window for this player.
                call TimerDialogDisplay(bj_crippledTimerWindows[playerIndex], false)

                // Display a confirmation message if the player's team is still alive.
                if (MeleeGetAllyStructureCount(indexPlayer) > 0) then
                    if (bj_playerIsExposed[playerIndex]) then
                        call DisplayTimedTextToPlayer(indexPlayer, 0, 0, bj_MELEE_CRIPPLE_MSG_DURATION, GetLocalizedString("CRIPPLE_UNREVEALED"))
                    else
                        call DisplayTimedTextToPlayer(indexPlayer, 0, 0, bj_MELEE_CRIPPLE_MSG_DURATION, GetLocalizedString("CRIPPLE_UNCRIPPLED"))
                    endif
                endif
            endif

            // If the player granted shared vision, deny that vision now.
            call MeleeExposePlayer(indexPlayer, false)

        endif
            
        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="MeleeCheckLostUnit" ReturnType="nothing" ArgumentList="unit lostUnit">
      <![CDATA[function MeleeCheckLostUnit takes unit lostUnit returns nothing
    local player lostUnitOwner = GetOwningPlayer(lostUnit)

    // We only need to check for mortality if this was the last building.
    if (GetPlayerStructureCount(lostUnitOwner, true) <= 0) then
        call MeleeCheckForLosersAndVictors()
    endif

    // Check if the lost unit has crippled or uncrippled the player.
    // (A team with 0 units is dead, and thus considered uncrippled.)
    call MeleeCheckForCrippledPlayers()
endfunction
]]>
    </Function>

    <Function Name="MeleeCheckAddedUnit" ReturnType="nothing" ArgumentList="unit addedUnit">
      <![CDATA[function MeleeCheckAddedUnit takes unit addedUnit returns nothing
    local player addedUnitOwner = GetOwningPlayer(addedUnit)

    // If the player was crippled, this unit may have uncrippled him/her.
    if (bj_playerIsCrippled[GetPlayerId(addedUnitOwner)]) then
        call MeleeCheckForCrippledPlayers()
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeTriggerActionConstructCancel" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeTriggerActionConstructCancel takes nothing returns nothing
    call MeleeCheckLostUnit(GetCancelledStructure())
endfunction
]]>
    </Function>

    <Function Name="MeleeTriggerActionUnitDeath" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeTriggerActionUnitDeath takes nothing returns nothing
    if (IsUnitType(GetDyingUnit(), UNIT_TYPE_STRUCTURE)) then
        call MeleeCheckLostUnit(GetDyingUnit())
    endif
endfunction
]]>
    </Function>

    <Function Name="MeleeTriggerActionUnitConstructionStart" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeTriggerActionUnitConstructionStart takes nothing returns nothing
    call MeleeCheckAddedUnit(GetConstructingStructure())
endfunction
]]>
    </Function>

    <Function Name="MeleeTriggerActionPlayerDefeated" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeTriggerActionPlayerDefeated takes nothing returns nothing
    local player thePlayer = GetTriggerPlayer()
	call CachePlayerHeroData(thePlayer)

    if (MeleeGetAllyCount(thePlayer) > 0) then
        // If at least one ally is still alive and kicking, share units with
        // them and proceed with death.
        call ShareEverythingWithTeam(thePlayer)
        if (not bj_meleeDefeated[GetPlayerId(thePlayer)]) then
            call MeleeDoDefeat(thePlayer)
        endif
    else
        // If no living allies remain, swap all units and buildings over to
        // neutral_passive and proceed with death.
        call MakeUnitsPassiveForTeam(thePlayer)
        if (not bj_meleeDefeated[GetPlayerId(thePlayer)]) then
            call MeleeDoDefeat(thePlayer)
        endif
    endif
    call MeleeCheckForLosersAndVictors()
endfunction
]]>
    </Function>

    <Function Name="MeleeTriggerActionPlayerLeft" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeTriggerActionPlayerLeft takes nothing returns nothing
    local player thePlayer = GetTriggerPlayer()

    // Just show game over for observers when they leave
    if (IsPlayerObserver(thePlayer)) then
        call RemovePlayerPreserveUnitsBJ(thePlayer, PLAYER_GAME_RESULT_NEUTRAL, false)
        return
    endif

	call CachePlayerHeroData(thePlayer)

    // This is the same as defeat except the player generates the message 
    // "player left the game" as opposed to "player was defeated".

    if (MeleeGetAllyCount(thePlayer) > 0) then
        // If at least one ally is still alive and kicking, share units with
        // them and proceed with death.
        call ShareEverythingWithTeam(thePlayer)
        call MeleeDoLeave(thePlayer)
    else
        // If no living allies remain, swap all units and buildings over to
        // neutral_passive and proceed with death.
        call MakeUnitsPassiveForTeam(thePlayer)
        call MeleeDoLeave(thePlayer)
    endif
    call MeleeCheckForLosersAndVictors()
endfunction
]]>
    </Function>

    <Function Name="MeleeTriggerActionAllianceChange" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeTriggerActionAllianceChange takes nothing returns nothing
    call MeleeCheckForLosersAndVictors()
    call MeleeCheckForCrippledPlayers()
endfunction
]]>
    </Function>

    <Function Name="MeleeTriggerTournamentFinishSoon" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeTriggerTournamentFinishSoon takes nothing returns nothing
    // Note: We may get this trigger multiple times
    local integer    playerIndex
    local player     indexPlayer
    local real       timeRemaining = GetTournamentFinishSoonTimeRemaining()

    if not bj_finishSoonAllExposed then
        set bj_finishSoonAllExposed = true

        // Reset all crippled players and their timers, and hide the local crippled timer dialog
        set playerIndex = 0
        loop
            set indexPlayer = Player(playerIndex)
            if bj_playerIsCrippled[playerIndex] then
                // Uncripple the player
                set bj_playerIsCrippled[playerIndex] = false
                call PauseTimer(bj_crippledTimer[playerIndex])

                if (GetLocalPlayer() == indexPlayer) then
                    // Use only local code (no net traffic) within this block to avoid desyncs.

                    // Hide the timer window.
                    call TimerDialogDisplay(bj_crippledTimerWindows[playerIndex], false)
                endif

            endif
            set playerIndex = playerIndex + 1
            exitwhen playerIndex == bj_MAX_PLAYERS
        endloop

        // Expose all players
        call MeleeExposeAllPlayers()
    endif

    // Show the "finish soon" timer dialog and set the real time remaining
    call TimerDialogDisplay(bj_finishSoonTimerDialog, true)
    call TimerDialogSetRealTimeRemaining(bj_finishSoonTimerDialog, timeRemaining)
endfunction
]]>
    </Function>

    <Function Name="MeleeWasUserPlayer" ReturnType="boolean" ArgumentList="player whichPlayer">
      <![CDATA[function MeleeWasUserPlayer takes player whichPlayer returns boolean
    local playerslotstate slotState

    if (GetPlayerController(whichPlayer) != MAP_CONTROL_USER) then
        return false
    endif

    set slotState = GetPlayerSlotState(whichPlayer)

    return (slotState == PLAYER_SLOT_STATE_PLAYING or slotState == PLAYER_SLOT_STATE_LEFT)
endfunction
]]>
    </Function>

    <Function Name="MeleeTournamentFinishNowRuleA" ReturnType="nothing" ArgumentList="integer multiplier">
      <![CDATA[function MeleeTournamentFinishNowRuleA takes integer multiplier returns nothing
    local integer array playerScore
    local integer array teamScore
    local force array   teamForce
    local integer       teamCount
    local integer       index
    local player        indexPlayer
    local integer       index2
    local player        indexPlayer2
    local integer       bestTeam
    local integer       bestScore
    local boolean       draw

    // Compute individual player scores
    set index = 0
    loop
        set indexPlayer = Player(index)
        if MeleeWasUserPlayer(indexPlayer) then
            set playerScore[index] = GetTournamentScore(indexPlayer)
            if playerScore[index] <= 0 then
                set playerScore[index] = 1
            endif
        else
            set playerScore[index] = 0
        endif
        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop

    // Compute team scores and team forces
    set teamCount = 0
    set index = 0
    loop
        if playerScore[index] != 0 then
            set indexPlayer = Player(index)

            set teamScore[teamCount] = 0
            set teamForce[teamCount] = CreateForce()

            set index2 = index
            loop
                if playerScore[index2] != 0 then
                    set indexPlayer2 = Player(index2)

                    if PlayersAreCoAllied(indexPlayer, indexPlayer2) then
                        set teamScore[teamCount] = teamScore[teamCount] + playerScore[index2]
                        call ForceAddPlayer(teamForce[teamCount], indexPlayer2)
                        set playerScore[index2] = 0
                    endif
                endif

                set index2 = index2 + 1
                exitwhen index2 == bj_MAX_PLAYERS
            endloop

            set teamCount = teamCount + 1
        endif

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop

    // The game is now over
    set bj_meleeGameOver = true

    // There should always be at least one team, but continue to work if not
    if teamCount != 0 then

        // Find best team score
        set bestTeam = -1
        set bestScore = -1
        set index = 0
        loop
            if teamScore[index] > bestScore then
                set bestTeam = index
                set bestScore = teamScore[index]
            endif

            set index = index + 1
            exitwhen index == teamCount
        endloop

        // Check whether the best team's score is 'multiplier' times better than
        // every other team. In the case of multiplier == 1 and exactly equal team
        // scores, the first team (which was randomly chosen by the server) will win.
        set draw = false
        set index = 0
        loop
            if index != bestTeam then
                if bestScore < (multiplier * teamScore[index]) then
                    set draw = true
                endif
            endif

            set index = index + 1
            exitwhen index == teamCount
        endloop

        if draw then
            // Give draw to all players on all teams
            set index = 0
            loop
                call ForForce(teamForce[index], function MeleeDoDrawEnum)

                set index = index + 1
                exitwhen index == teamCount
            endloop
        else
            // Give defeat to all players on teams other than the best team
            set index = 0
            loop
                if index != bestTeam then
                    call ForForce(teamForce[index], function MeleeDoDefeatEnum)
                endif

                set index = index + 1
                exitwhen index == teamCount
            endloop

            // Give victory to all players on the best team
            call ForForce(teamForce[bestTeam], function MeleeDoVictoryEnum)
        endif
    endif

endfunction
]]>
    </Function>

    <Function Name="MeleeTriggerTournamentFinishNow" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeTriggerTournamentFinishNow takes nothing returns nothing
    local integer rule = GetTournamentFinishNowRule()

    // If the game is already over, do nothing
    if bj_meleeGameOver then
        return
    endif

    if (rule == 1) then
        // Finals games
        call MeleeTournamentFinishNowRuleA(1)
    else
        // Preliminary games
        call MeleeTournamentFinishNowRuleA(3)
    endif

    // Since the game is over we should remove all observers
    call MeleeRemoveObservers()

endfunction
]]>
    </Function>

    <Function Name="MeleeInitVictoryDefeat" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeInitVictoryDefeat takes nothing returns nothing
    local trigger    trig
    local integer    index
    local player     indexPlayer

    // Create a timer window for the "finish soon" timeout period, it has no timer
    // because it is driven by real time (outside of the game state to avoid desyncs)
    set bj_finishSoonTimerDialog = CreateTimerDialog(null)

    // Set a trigger to fire when we receive a "finish soon" game event
    set trig = CreateTrigger()
    call TriggerRegisterGameEvent(trig, EVENT_GAME_TOURNAMENT_FINISH_SOON)
    call TriggerAddAction(trig, function MeleeTriggerTournamentFinishSoon)

    // Set a trigger to fire when we receive a "finish now" game event
    set trig = CreateTrigger()
    call TriggerRegisterGameEvent(trig, EVENT_GAME_TOURNAMENT_FINISH_NOW)
    call TriggerAddAction(trig, function MeleeTriggerTournamentFinishNow)

    // Set up each player's mortality code.
    set index = 0
    loop
        set indexPlayer = Player(index)

        // Make sure this player slot is playing.
        if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
            set bj_meleeDefeated[index] = false
            set bj_meleeVictoried[index] = false

            // Create a timer and timer window in case the player is crippled.
            set bj_playerIsCrippled[index] = false
            set bj_playerIsExposed[index] = false
            set bj_crippledTimer[index] = CreateTimer()
            set bj_crippledTimerWindows[index] = CreateTimerDialog(bj_crippledTimer[index])
            call TimerDialogSetTitle(bj_crippledTimerWindows[index], MeleeGetCrippledTimerMessage(indexPlayer))

            // Set a trigger to fire whenever a building is cancelled for this player.
            set trig = CreateTrigger()
            call TriggerRegisterPlayerUnitEvent(trig, indexPlayer, EVENT_PLAYER_UNIT_CONSTRUCT_CANCEL, null)
            call TriggerAddAction(trig, function MeleeTriggerActionConstructCancel)

            // Set a trigger to fire whenever a unit dies for this player.
            set trig = CreateTrigger()
            call TriggerRegisterPlayerUnitEvent(trig, indexPlayer, EVENT_PLAYER_UNIT_DEATH, null)
            call TriggerAddAction(trig, function MeleeTriggerActionUnitDeath)

            // Set a trigger to fire whenever a unit begins construction for this player
            set trig = CreateTrigger()
            call TriggerRegisterPlayerUnitEvent(trig, indexPlayer, EVENT_PLAYER_UNIT_CONSTRUCT_START, null)
            call TriggerAddAction(trig, function MeleeTriggerActionUnitConstructionStart)

            // Set a trigger to fire whenever this player defeats-out
            set trig = CreateTrigger()
            call TriggerRegisterPlayerEvent(trig, indexPlayer, EVENT_PLAYER_DEFEAT)
            call TriggerAddAction(trig, function MeleeTriggerActionPlayerDefeated)

            // Set a trigger to fire whenever this player leaves
            set trig = CreateTrigger()
            call TriggerRegisterPlayerEvent(trig, indexPlayer, EVENT_PLAYER_LEAVE)
            call TriggerAddAction(trig, function MeleeTriggerActionPlayerLeft)

            // Set a trigger to fire whenever this player changes his/her alliances.
            set trig = CreateTrigger()
            call TriggerRegisterPlayerAllianceChange(trig, indexPlayer, ALLIANCE_PASSIVE)
            call TriggerRegisterPlayerStateEvent(trig, indexPlayer, PLAYER_STATE_ALLIED_VICTORY, EQUAL, 1)
            call TriggerAddAction(trig, function MeleeTriggerActionAllianceChange)
        else
            set bj_meleeDefeated[index] = true
            set bj_meleeVictoried[index] = false

            // Handle leave events for observers
            if (IsPlayerObserver(indexPlayer)) then
                // Set a trigger to fire whenever this player leaves
                set trig = CreateTrigger()
                call TriggerRegisterPlayerEvent(trig, indexPlayer, EVENT_PLAYER_LEAVE)
                call TriggerAddAction(trig, function MeleeTriggerActionPlayerLeft)
            endif
        endif

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop

    // Test for victory / defeat at startup, in case the user has already won / lost.
    // Allow for a short time to pass first, so that the map can finish loading.
    call TimerStart(CreateTimer(), 2.0, false, function MeleeTriggerActionAllianceChange)
endfunction
]]>
    </Function>

    <Function Name="CheckInitPlayerSlotAvailability" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function CheckInitPlayerSlotAvailability takes nothing returns nothing
    local integer index

    if (not bj_slotControlReady) then
        set index = 0
        loop
            set bj_slotControlUsed[index] = false
            set bj_slotControl[index] = MAP_CONTROL_USER
            set index = index + 1
            exitwhen index == bj_MAX_PLAYERS
        endloop
        set bj_slotControlReady = true
    endif
endfunction
]]>
    </Function>

    <Function Name="SetPlayerSlotAvailable" ReturnType="nothing" ArgumentList="player whichPlayer, mapcontrol control">
      <![CDATA[function SetPlayerSlotAvailable takes player whichPlayer, mapcontrol control returns nothing
    local integer playerIndex = GetPlayerId(whichPlayer)

    call CheckInitPlayerSlotAvailability()
    set bj_slotControlUsed[playerIndex] = true
    set bj_slotControl[playerIndex] = control
endfunction
]]>
    </Function>

    <Function Name="TeamInitPlayerSlots" ReturnType="nothing" ArgumentList="integer teamCount">
      <![CDATA[function TeamInitPlayerSlots takes integer teamCount returns nothing
    local integer index
    local player  indexPlayer
    local integer team

    call SetTeams(teamCount)

    call CheckInitPlayerSlotAvailability()
    set index = 0
    set team = 0
    loop
        if (bj_slotControlUsed[index]) then
            set indexPlayer = Player(index)
            call SetPlayerTeam( indexPlayer, team )
            set team = team + 1
            if (team >= teamCount) then
                set team = 0
            endif
        endif

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="MeleeInitPlayerSlots" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MeleeInitPlayerSlots takes nothing returns nothing
    call TeamInitPlayerSlots(bj_MAX_PLAYERS)
endfunction
]]>
    </Function>

    <Function Name="FFAInitPlayerSlots" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function FFAInitPlayerSlots takes nothing returns nothing
    call TeamInitPlayerSlots(bj_MAX_PLAYERS)
endfunction
]]>
    </Function>

    <Function Name="OneOnOneInitPlayerSlots" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function OneOnOneInitPlayerSlots takes nothing returns nothing
    // Limit the game to 2 players.
    call SetTeams(2)
    call SetPlayers(2)
    call TeamInitPlayerSlots(2)
endfunction
]]>
    </Function>

    <Function Name="InitGenericPlayerSlots" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitGenericPlayerSlots takes nothing returns nothing
    local gametype gType = GetGameTypeSelected()

    if (gType == GAME_TYPE_MELEE) then
        call MeleeInitPlayerSlots()
    elseif (gType == GAME_TYPE_FFA) then
        call FFAInitPlayerSlots()
    elseif (gType == GAME_TYPE_USE_MAP_SETTINGS) then
        // Do nothing; the map-specific script handles this.
    elseif (gType == GAME_TYPE_ONE_ON_ONE) then
        call OneOnOneInitPlayerSlots()
    elseif (gType == GAME_TYPE_TWO_TEAM_PLAY) then
        call TeamInitPlayerSlots(2)
    elseif (gType == GAME_TYPE_THREE_TEAM_PLAY) then
        call TeamInitPlayerSlots(3)
    elseif (gType == GAME_TYPE_FOUR_TEAM_PLAY) then
        call TeamInitPlayerSlots(4)
    else
        // Unrecognized Game Type
    endif
endfunction
]]>
    </Function>

    <Function Name="SetDNCSoundsDawn" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetDNCSoundsDawn takes nothing returns nothing
    if bj_useDawnDuskSounds then
        call StartSound(bj_dawnSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetDNCSoundsDusk" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetDNCSoundsDusk takes nothing returns nothing
    if bj_useDawnDuskSounds then
        call StartSound(bj_duskSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetDNCSoundsDay" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetDNCSoundsDay takes nothing returns nothing
    local real ToD = GetTimeOfDay()

    if (ToD >= bj_TOD_DAWN and ToD < bj_TOD_DUSK) and not bj_dncIsDaytime then
        set bj_dncIsDaytime = true

        // change ambient sounds
        call StopSound(bj_nightAmbientSound, false, true)
        call StartSound(bj_dayAmbientSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="SetDNCSoundsNight" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function SetDNCSoundsNight takes nothing returns nothing
    local real ToD = GetTimeOfDay()

    if (ToD < bj_TOD_DAWN or ToD >= bj_TOD_DUSK) and bj_dncIsDaytime then
        set bj_dncIsDaytime = false

        // change ambient sounds
        call StopSound(bj_dayAmbientSound, false, true)
        call StartSound(bj_nightAmbientSound)
    endif
endfunction
]]>
    </Function>

    <Function Name="InitDNCSounds" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitDNCSounds takes nothing returns nothing
    // Create sounds to be played at dawn and dusk.
    set bj_dawnSound = CreateSoundFromLabel("RoosterSound", false, false, false, 10000, 10000)
    set bj_duskSound = CreateSoundFromLabel("WolfSound", false, false, false, 10000, 10000)

    // Set up triggers to respond to dawn and dusk.
    set bj_dncSoundsDawn = CreateTrigger()
    call TriggerRegisterGameStateEvent(bj_dncSoundsDawn, GAME_STATE_TIME_OF_DAY, EQUAL, bj_TOD_DAWN)
    call TriggerAddAction(bj_dncSoundsDawn, function SetDNCSoundsDawn)

    set bj_dncSoundsDusk = CreateTrigger()
    call TriggerRegisterGameStateEvent(bj_dncSoundsDusk, GAME_STATE_TIME_OF_DAY, EQUAL, bj_TOD_DUSK)
    call TriggerAddAction(bj_dncSoundsDusk, function SetDNCSoundsDusk)

    // Set up triggers to respond to changes from day to night or vice-versa.
    set bj_dncSoundsDay = CreateTrigger()
    call TriggerRegisterGameStateEvent(bj_dncSoundsDay,   GAME_STATE_TIME_OF_DAY, GREATER_THAN_OR_EQUAL, bj_TOD_DAWN)
    call TriggerRegisterGameStateEvent(bj_dncSoundsDay,   GAME_STATE_TIME_OF_DAY, LESS_THAN,             bj_TOD_DUSK)
    call TriggerAddAction(bj_dncSoundsDay, function SetDNCSoundsDay)

    set bj_dncSoundsNight = CreateTrigger()
    call TriggerRegisterGameStateEvent(bj_dncSoundsNight, GAME_STATE_TIME_OF_DAY, LESS_THAN,             bj_TOD_DAWN)
    call TriggerRegisterGameStateEvent(bj_dncSoundsNight, GAME_STATE_TIME_OF_DAY, GREATER_THAN_OR_EQUAL, bj_TOD_DUSK)
    call TriggerAddAction(bj_dncSoundsNight, function SetDNCSoundsNight)
endfunction
]]>
    </Function>

    <Function Name="InitBlizzardGlobals" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitBlizzardGlobals takes nothing returns nothing
    local integer index
    local integer userControlledPlayers
    local version v

    // Init filter function vars
    set filterIssueHauntOrderAtLocBJ = Filter(function IssueHauntOrderAtLocBJFilter)
    set filterEnumDestructablesInCircleBJ = Filter(function EnumDestructablesInCircleBJFilter)
    set filterGetUnitsInRectOfPlayer = Filter(function GetUnitsInRectOfPlayerFilter)
    set filterGetUnitsOfTypeIdAll = Filter(function GetUnitsOfTypeIdAllFilter)
    set filterGetUnitsOfPlayerAndTypeId = Filter(function GetUnitsOfPlayerAndTypeIdFilter)
    set filterMeleeTrainedUnitIsHeroBJ = Filter(function MeleeTrainedUnitIsHeroBJFilter)
    set filterLivingPlayerUnitsOfTypeId = Filter(function LivingPlayerUnitsOfTypeIdFilter)

    // Init force presets
    set index = 0
    loop
        exitwhen index == bj_MAX_PLAYER_SLOTS
        set bj_FORCE_PLAYER[index] = CreateForce()
        call ForceAddPlayer(bj_FORCE_PLAYER[index], Player(index))
        set index = index + 1
    endloop

    set bj_FORCE_ALL_PLAYERS = CreateForce()
    call ForceEnumPlayers(bj_FORCE_ALL_PLAYERS, null)

    // Init Cinematic Mode history
    set bj_cineModePriorSpeed = GetGameSpeed()
    set bj_cineModePriorFogSetting = IsFogEnabled()
    set bj_cineModePriorMaskSetting = IsFogMaskEnabled()

    // Init Trigger Queue
    set index = 0
    loop
        exitwhen index >= bj_MAX_QUEUED_TRIGGERS
        set bj_queuedExecTriggers[index] = null
        set bj_queuedExecUseConds[index] = false
        set index = index + 1
    endloop

    // Init singleplayer check
    set bj_isSinglePlayer = false
    set userControlledPlayers = 0
    set index = 0
    loop
        exitwhen index >= bj_MAX_PLAYERS
        if (GetPlayerController(Player(index)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(index)) == PLAYER_SLOT_STATE_PLAYING) then
            set userControlledPlayers = userControlledPlayers + 1
        endif
        set index = index + 1
    endloop
    set bj_isSinglePlayer = (userControlledPlayers == 1)

    // Init sounds
    //set bj_pingMinimapSound = CreateSoundFromLabel("AutoCastButtonClick", false, false, false, 10000, 10000)
    set bj_rescueSound = CreateSoundFromLabel("Rescue", false, false, false, 10000, 10000)
    set bj_questDiscoveredSound = CreateSoundFromLabel("QuestNew", false, false, false, 10000, 10000)
    set bj_questUpdatedSound = CreateSoundFromLabel("QuestUpdate", false, false, false, 10000, 10000)
    set bj_questCompletedSound = CreateSoundFromLabel("QuestCompleted", false, false, false, 10000, 10000)
    set bj_questFailedSound = CreateSoundFromLabel("QuestFailed", false, false, false, 10000, 10000)
    set bj_questHintSound = CreateSoundFromLabel("Hint", false, false, false, 10000, 10000)
    set bj_questSecretSound = CreateSoundFromLabel("SecretFound", false, false, false, 10000, 10000)
    set bj_questItemAcquiredSound = CreateSoundFromLabel("ItemReward", false, false, false, 10000, 10000)
    set bj_questWarningSound = CreateSoundFromLabel("Warning", false, false, false, 10000, 10000)
    set bj_victoryDialogSound = CreateSoundFromLabel("QuestCompleted", false, false, false, 10000, 10000)
    set bj_defeatDialogSound = CreateSoundFromLabel("QuestFailed", false, false, false, 10000, 10000)

    // Init corpse creation triggers.
    call DelayedSuspendDecayCreate()

    // Init version-specific data
    set v = VersionGet()
    if (v == VERSION_REIGN_OF_CHAOS) then
        set bj_MELEE_MAX_TWINKED_HEROES = bj_MELEE_MAX_TWINKED_HEROES_V0
    else
        set bj_MELEE_MAX_TWINKED_HEROES = bj_MELEE_MAX_TWINKED_HEROES_V1
    endif
endfunction
]]>
    </Function>

    <Function Name="InitQueuedTriggers" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitQueuedTriggers takes nothing returns nothing
    set bj_queuedExecTimeout = CreateTrigger()
    call TriggerRegisterTimerExpireEvent(bj_queuedExecTimeout, bj_queuedExecTimeoutTimer)
    call TriggerAddAction(bj_queuedExecTimeout, function QueuedTriggerDoneBJ)
endfunction
]]>
    </Function>

    <Function Name="InitMapRects" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitMapRects takes nothing returns nothing
    set bj_mapInitialPlayableArea = Rect(GetCameraBoundMinX()-GetCameraMargin(CAMERA_MARGIN_LEFT), GetCameraBoundMinY()-GetCameraMargin(CAMERA_MARGIN_BOTTOM), GetCameraBoundMaxX()+GetCameraMargin(CAMERA_MARGIN_RIGHT), GetCameraBoundMaxY()+GetCameraMargin(CAMERA_MARGIN_TOP))
    set bj_mapInitialCameraBounds = GetCurrentCameraBoundsMapRectBJ()
endfunction
]]>
    </Function>

    <Function Name="InitSummonableCaps" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitSummonableCaps takes nothing returns nothing
    local integer index

    set index = 0
    loop
        // upgraded units
        call SetPlayerTechMaxAllowed(Player(index), 'hrtt', 0)
        call SetPlayerTechMaxAllowed(Player(index), 'otbk', 0)

        // max skeletons per player
        call SetPlayerTechMaxAllowed(Player(index), 'uske', bj_MAX_SKELETONS)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYERS
    endloop
endfunction
]]>
    </Function>

    <Function Name="UpdateStockAvailability" ReturnType="nothing" ArgumentList="item whichItem">
      <![CDATA[function UpdateStockAvailability takes item whichItem returns nothing
    local itemtype iType  = GetItemType(whichItem)
    local integer  iLevel = GetItemLevel(whichItem)

    // Update allowed type/level combinations.
    if (iType == ITEM_TYPE_PERMANENT) then
        set bj_stockAllowedPermanent[iLevel] = true
    elseif (iType == ITEM_TYPE_CHARGED) then
        set bj_stockAllowedCharged[iLevel] = true
    elseif (iType == ITEM_TYPE_ARTIFACT) then
        set bj_stockAllowedArtifact[iLevel] = true
    else
        // Not interested in this item type - ignore the item.
    endif
endfunction
]]>
    </Function>

    <Function Name="UpdateEachStockBuildingEnum" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function UpdateEachStockBuildingEnum takes nothing returns nothing
    local integer iteration = 0
    local integer pickedItemId

    loop
        set pickedItemId = ChooseRandomItemEx(bj_stockPickedItemType, bj_stockPickedItemLevel)
        exitwhen IsItemIdSellable(pickedItemId)

        // If we get hung up on an entire class/level combo of unsellable
        // items, or a very unlucky series of random numbers, give up.
        set iteration = iteration + 1
        if (iteration > bj_STOCK_MAX_ITERATIONS) then
            return
        endif
    endloop
    call AddItemToStock(GetEnumUnit(), pickedItemId, 1, 1)
endfunction
]]>
    </Function>

    <Function Name="UpdateEachStockBuilding" ReturnType="nothing" ArgumentList="itemtype iType, integer iLevel">
      <![CDATA[function UpdateEachStockBuilding takes itemtype iType, integer iLevel returns nothing
    local group g

    set bj_stockPickedItemType = iType
    set bj_stockPickedItemLevel = iLevel

    set g = CreateGroup()
    call GroupEnumUnitsOfType(g, "marketplace", null)
    call ForGroup(g, function UpdateEachStockBuildingEnum)
    call DestroyGroup(g)
endfunction
]]>
    </Function>

    <Function Name="PerformStockUpdates" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function PerformStockUpdates takes nothing returns nothing
    local integer  pickedItemId
    local itemtype pickedItemType
    local integer  pickedItemLevel = 0
    local integer  allowedCombinations = 0
    local integer  iLevel

    // Give each type/level combination a chance of being picked.
    set iLevel = 1
    loop
        if (bj_stockAllowedPermanent[iLevel]) then
            set allowedCombinations = allowedCombinations + 1
            if (GetRandomInt(1, allowedCombinations) == 1) then
                set pickedItemType = ITEM_TYPE_PERMANENT
                set pickedItemLevel = iLevel
            endif
        endif
        if (bj_stockAllowedCharged[iLevel]) then
            set allowedCombinations = allowedCombinations + 1
            if (GetRandomInt(1, allowedCombinations) == 1) then
                set pickedItemType = ITEM_TYPE_CHARGED
                set pickedItemLevel = iLevel
            endif
        endif
        if (bj_stockAllowedArtifact[iLevel]) then
            set allowedCombinations = allowedCombinations + 1
            if (GetRandomInt(1, allowedCombinations) == 1) then
                set pickedItemType = ITEM_TYPE_ARTIFACT
                set pickedItemLevel = iLevel
            endif
        endif

        set iLevel = iLevel + 1
        exitwhen iLevel > bj_MAX_ITEM_LEVEL
    endloop

    // Make sure we found a valid item type to add.
    if (allowedCombinations == 0) then
        return
    endif

    call UpdateEachStockBuilding(pickedItemType, pickedItemLevel)
endfunction
]]>
    </Function>

    <Function Name="StartStockUpdates" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function StartStockUpdates takes nothing returns nothing
    call PerformStockUpdates()
    call TimerStart(bj_stockUpdateTimer, bj_STOCK_RESTOCK_INTERVAL, true, function PerformStockUpdates)
endfunction
]]>
    </Function>

    <Function Name="RemovePurchasedItem" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function RemovePurchasedItem takes nothing returns nothing
    call RemoveItemFromStock(GetSellingUnit(), GetItemTypeId(GetSoldItem()))
endfunction
]]>
    </Function>

    <Function Name="InitNeutralBuildings" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitNeutralBuildings takes nothing returns nothing
    local integer iLevel

    // Chart of allowed stock items.
    set iLevel = 0
    loop
        set bj_stockAllowedPermanent[iLevel] = false
        set bj_stockAllowedCharged[iLevel] = false
        set bj_stockAllowedArtifact[iLevel] = false
        set iLevel = iLevel + 1
        exitwhen iLevel > bj_MAX_ITEM_LEVEL
    endloop

    // Limit stock inventory slots.
    call SetAllItemTypeSlots(bj_MAX_STOCK_ITEM_SLOTS)
    call SetAllUnitTypeSlots(bj_MAX_STOCK_UNIT_SLOTS)

    // Arrange the first update.
    set bj_stockUpdateTimer = CreateTimer()
    call TimerStart(bj_stockUpdateTimer, bj_STOCK_RESTOCK_INITIAL_DELAY, false, function StartStockUpdates)

    // Set up a trigger to fire whenever an item is sold.
    set bj_stockItemPurchased = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(bj_stockItemPurchased, Player(PLAYER_NEUTRAL_PASSIVE), EVENT_PLAYER_UNIT_SELL_ITEM, null)
    call TriggerAddAction(bj_stockItemPurchased, function RemovePurchasedItem)
endfunction
]]>
    </Function>

    <Function Name="MarkGameStarted" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function MarkGameStarted takes nothing returns nothing
    set bj_gameStarted = true
    call DestroyTimer(bj_gameStartedTimer)
endfunction
]]>
    </Function>

    <Function Name="DetectGameStarted" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function DetectGameStarted takes nothing returns nothing
    set bj_gameStartedTimer = CreateTimer()
    call TimerStart(bj_gameStartedTimer, bj_GAME_STARTED_THRESHOLD, false, function MarkGameStarted)
endfunction
]]>
    </Function>

    <Function Name="InitBlizzard" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function InitBlizzard takes nothing returns nothing
    // Set up the Neutral Victim player slot, to torture the abandoned units
    // of defeated players.  Since some triggers expect this player slot to
    // exist, this is performed for all maps.
    call ConfigureNeutralVictim()

    call InitBlizzardGlobals()
    call InitQueuedTriggers()
    call InitRescuableBehaviorBJ()
    call InitDNCSounds()
    call InitMapRects()
    call InitSummonableCaps()
    call InitNeutralBuildings()
    call DetectGameStarted()
endfunction
]]>
    </Function>

    <Function Name="RandomDistReset" ReturnType="nothing" ArgumentList="nothing">
      <![CDATA[function RandomDistReset takes nothing returns nothing
    set bj_randDistCount = 0
endfunction
]]>
    </Function>

    <Function Name="RandomDistAddItem" ReturnType="nothing" ArgumentList="integer inID, integer inChance">
      <![CDATA[function RandomDistAddItem takes integer inID, integer inChance returns nothing
    set bj_randDistID[bj_randDistCount] = inID
    set bj_randDistChance[bj_randDistCount] = inChance
    set bj_randDistCount = bj_randDistCount + 1
endfunction
]]>
    </Function>

    <Function Name="RandomDistChoose" ReturnType="integer" ArgumentList="nothing">
      <![CDATA[function RandomDistChoose takes nothing returns integer
    local integer sum = 0
	local integer chance = 0
	local integer index
	local integer foundID = -1
	local boolean done

	// No items?
	if (bj_randDistCount == 0) then
        return -1
    endif

	// Find sum of all chances
	set index = 0
	loop
        set sum = sum + bj_randDistChance[index]

		set index = index + 1
        exitwhen index == bj_randDistCount
    endloop

	// Choose random number within the total range
	set chance = GetRandomInt(1, sum)

	// Find ID which corresponds to this chance
	set index = 0
	set sum = 0
	set done = false
	loop
        set sum = sum + bj_randDistChance[index]

		if (chance <= sum) then
            set foundID = bj_randDistID[index]
			set done = true
		endif

		set index = index + 1
		if (index == bj_randDistCount) then
            set done = true
		endif

        exitwhen done == true
    endloop

	return foundID
endfunction
]]>
    </Function>

    <Function Name="UnitDropItem" ReturnType="item" ArgumentList="unit inUnit, integer inItemID">
      <![CDATA[function UnitDropItem takes unit inUnit, integer inItemID returns item
    local real x
	local real y
	local real radius = 32
	local real unitX
	local real unitY
    local item droppedItem

	if (inItemID == -1) then
        return null
    endif

    set unitX = GetUnitX(inUnit)
	set unitY = GetUnitY(inUnit)

	set x = GetRandomReal(unitX - radius, unitX + radius)
	set y = GetRandomReal(unitY - radius, unitY + radius)

    set droppedItem = CreateItem(inItemID, x, y)

    call SetItemDropID(droppedItem, GetUnitTypeId(inUnit))
    call UpdateStockAvailability(droppedItem)

    return droppedItem
endfunction
]]>
    </Function>

    <Function Name="WidgetDropItem" ReturnType="item" ArgumentList="widget inWidget, integer inItemID">
      <![CDATA[function WidgetDropItem takes widget inWidget, integer inItemID returns item
    local real x
	local real y
	local real radius = 32
	local real widgetX
	local real widgetY

	if (inItemID == -1) then
        return null
    endif

    set widgetX = GetWidgetX(inWidget)
	set widgetY = GetWidgetY(inWidget)

	set x = GetRandomReal(widgetX - radius, widgetX + radius)
	set y = GetRandomReal(widgetY - radius, widgetY + radius)

    return CreateItem(inItemID, x, y)
endfunction]]>
    </Function>
  </BJs>
</Jass>